Class: Markbridge::AST::Quote

Inherits:
Element show all
Defined in:
lib/markbridge/ast/quote.rb

Overview

Represents a quote/blockquote element.

The attribution fields follow Discourse's quote format ([quote="username, post:2, topic:456"]): post_number is the position of the quoted post within its topic (not a database id), topic_id is the topic's id. Sources that attribute quotes by database id instead (phpBB, XenForo) use post_id and user_id — those never feed a Discourse post: reference and are carried for consumers to remap.

Examples:

Basic quote

quote = AST::Quote.new
quote << AST::Text.new("quoted text")

Quote with author attribution

quote = AST::Quote.new(author: "alice")
quote << AST::Text.new("quoted text")

Quote with full Discourse context

quote = AST::Quote.new(author: "alice", post_number: 123, topic_id: 456, username: "alice_b")
quote << AST::Text.new("quoted text")

Instance Attribute Summary collapse

Attributes inherited from Element

#children

Instance Method Summary collapse

Methods inherited from Element

#<<, #descendants, #each_descendant, #replace_child

Constructor Details

#initialize(author: nil, post_number: nil, post_id: nil, topic_id: nil, username: nil, user_id: nil) ⇒ Quote

Create a new Quote element.

Parameters:

  • author (String, nil) (defaults to: nil)

    the author attribution (display name)

  • post_number (Integer, nil) (defaults to: nil)

    the quoted post's number within its topic

  • post_id (Integer, nil) (defaults to: nil)

    the quoted post's database id

  • topic_id (Integer, nil) (defaults to: nil)

    the topic id

  • username (String, nil) (defaults to: nil)

    the quoted user's username

  • user_id (Integer, nil) (defaults to: nil)

    the quoted user's id



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/markbridge/ast/quote.rb', line 58

def initialize(
  author: nil,
  post_number: nil,
  post_id: nil,
  topic_id: nil,
  username: nil,
  user_id: nil
)
  super()
  @author = author
  @post_number = post_number
  @post_id = post_id
  @topic_id = topic_id
  @username = username
  @user_id = user_id
end

Instance Attribute Details

#authorString? (readonly)

Returns the author attribution (display name).

Returns:

  • (String, nil)

    the author attribution (display name)



28
29
30
# File 'lib/markbridge/ast/quote.rb', line 28

def author
  @author
end

#post_idInteger? (readonly)

Returns the quoted post's database id, for sources that attribute quotes by id (phpBB's post_id, XenForo's post:). Distinct from #post_number; parsers map whichever their dialect provides.

Returns:

  • (Integer, nil)

    the quoted post's database id, for sources that attribute quotes by id (phpBB's post_id, XenForo's post:). Distinct from #post_number; parsers map whichever their dialect provides.



38
39
40
# File 'lib/markbridge/ast/quote.rb', line 38

def post_id
  @post_id
end

#post_numberInteger? (readonly)

Returns the quoted post's number within its topic (Discourse semantics — not a post id).

Returns:

  • (Integer, nil)

    the quoted post's number within its topic (Discourse semantics — not a post id)



32
33
34
# File 'lib/markbridge/ast/quote.rb', line 32

def post_number
  @post_number
end

#topic_idInteger? (readonly)

Returns the topic id the quoted post belongs to.

Returns:

  • (Integer, nil)

    the topic id the quoted post belongs to



41
42
43
# File 'lib/markbridge/ast/quote.rb', line 41

def topic_id
  @topic_id
end

#user_idInteger? (readonly)

Returns the quoted user's id, for sources that attribute quotes by id (usernames may be unknown or stale).

Returns:

  • (Integer, nil)

    the quoted user's id, for sources that attribute quotes by id (usernames may be unknown or stale)



48
49
50
# File 'lib/markbridge/ast/quote.rb', line 48

def user_id
  @user_id
end

#usernameString? (readonly)

Returns the quoted user's username.

Returns:

  • (String, nil)

    the quoted user's username



44
45
46
# File 'lib/markbridge/ast/quote.rb', line 44

def username
  @username
end