coradoc-markdown 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/lib/coradoc/markdown/errors.rb +28 -0
  4. data/lib/coradoc/markdown/model/abbreviation.rb +27 -0
  5. data/lib/coradoc/markdown/model/attribute_list.rb +98 -0
  6. data/lib/coradoc/markdown/model/base.rb +86 -0
  7. data/lib/coradoc/markdown/model/blockquote.rb +21 -0
  8. data/lib/coradoc/markdown/model/code.rb +11 -0
  9. data/lib/coradoc/markdown/model/code_block.rb +24 -0
  10. data/lib/coradoc/markdown/model/definition_item.rb +24 -0
  11. data/lib/coradoc/markdown/model/definition_list.rb +47 -0
  12. data/lib/coradoc/markdown/model/definition_term.rb +21 -0
  13. data/lib/coradoc/markdown/model/document.rb +39 -0
  14. data/lib/coradoc/markdown/model/emphasis.rb +11 -0
  15. data/lib/coradoc/markdown/model/extension.rb +92 -0
  16. data/lib/coradoc/markdown/model/footnote.rb +31 -0
  17. data/lib/coradoc/markdown/model/footnote_reference.rb +22 -0
  18. data/lib/coradoc/markdown/model/heading.rb +44 -0
  19. data/lib/coradoc/markdown/model/highlight.rb +18 -0
  20. data/lib/coradoc/markdown/model/horizontal_rule.rb +16 -0
  21. data/lib/coradoc/markdown/model/image.rb +19 -0
  22. data/lib/coradoc/markdown/model/link.rb +19 -0
  23. data/lib/coradoc/markdown/model/list.rb +22 -0
  24. data/lib/coradoc/markdown/model/list_item.rb +29 -0
  25. data/lib/coradoc/markdown/model/math.rb +50 -0
  26. data/lib/coradoc/markdown/model/paragraph.rb +28 -0
  27. data/lib/coradoc/markdown/model/strikethrough.rb +18 -0
  28. data/lib/coradoc/markdown/model/strong.rb +11 -0
  29. data/lib/coradoc/markdown/model/table.rb +13 -0
  30. data/lib/coradoc/markdown/model/text.rb +15 -0
  31. data/lib/coradoc/markdown/parser/ast_processor.rb +543 -0
  32. data/lib/coradoc/markdown/parser/block_parser.rb +745 -0
  33. data/lib/coradoc/markdown/parser/html_entities.rb +2149 -0
  34. data/lib/coradoc/markdown/parser/inline_parser.rb +274 -0
  35. data/lib/coradoc/markdown/parser/parslet_extras.rb +215 -0
  36. data/lib/coradoc/markdown/parser.rb +11 -0
  37. data/lib/coradoc/markdown/parser_util.rb +90 -0
  38. data/lib/coradoc/markdown/serializer.rb +199 -0
  39. data/lib/coradoc/markdown/toc_generator.rb +215 -0
  40. data/lib/coradoc/markdown/transform/from_core_model.rb +325 -0
  41. data/lib/coradoc/markdown/transform/text_extraction.rb +19 -0
  42. data/lib/coradoc/markdown/transform/to_core_model.rb +287 -0
  43. data/lib/coradoc/markdown/transformer.rb +463 -0
  44. data/lib/coradoc/markdown/version.rb +7 -0
  45. data/lib/coradoc/markdown.rb +190 -0
  46. metadata +173 -0
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # HorizontalRule model representing a Markdown horizontal rule (---, ***, ___).
6
+ #
7
+ class HorizontalRule < Base
8
+ attribute :style, :string, default: '---' # ---, ***, or ___
9
+
10
+ def initialize(style: '---')
11
+ super()
12
+ @style = style
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # Image model representing a Markdown image ![alt](src).
6
+ #
7
+ # @example Create an image
8
+ # img = Coradoc::Markdown::Image.new(
9
+ # alt: "Logo",
10
+ # src: "/images/logo.png"
11
+ # )
12
+ #
13
+ class Image < Base
14
+ attribute :alt, :string
15
+ attribute :src, :string
16
+ attribute :title, :string # Optional title
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # Link model representing a Markdown link [text](url).
6
+ #
7
+ # @example Create a link
8
+ # link = Coradoc::Markdown::Link.new(
9
+ # text: "Example",
10
+ # url: "https://example.com"
11
+ # )
12
+ #
13
+ class Link < Base
14
+ attribute :text, :string
15
+ attribute :url, :string
16
+ attribute :title, :string # Optional title
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # List model representing a Markdown list (ordered or unordered).
6
+ #
7
+ # @example Create an unordered list
8
+ # list = Coradoc::Markdown::List.new(
9
+ # ordered: false,
10
+ # items: [
11
+ # Coradoc::Markdown::ListItem.new(text: "Item 1"),
12
+ # Coradoc::Markdown::ListItem.new(text: "Item 2")
13
+ # ]
14
+ # )
15
+ #
16
+ class List < Base
17
+ attribute :ordered, :boolean, default: false
18
+ attribute :items, Coradoc::Markdown::ListItem, collection: true
19
+ attribute :start_number, :integer, default: 1
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # ListItem model representing an item in a Markdown list.
6
+ #
7
+ class ListItem < Base
8
+ attribute :text, :string
9
+ attribute :checked, :boolean # For task lists (- [ ] or - [x])
10
+ attribute :sublist, Coradoc::Markdown::List # Nested list
11
+
12
+ # Mixed content (strings and inline model objects)
13
+ # @return [Array] mixed content array
14
+ attr_reader :children
15
+
16
+ def initialize(args = {})
17
+ super()
18
+ @text = args[:text] || ''
19
+ @checked = args[:checked]
20
+ @sublist = args[:sublist]
21
+ @children = args[:children] || []
22
+ end
23
+
24
+ def children=(value)
25
+ @children = value || []
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ module Coradoc
5
+ module Markdown
6
+ # Represents a math block (block or inline)
7
+ #
8
+ # Block math syntax: $$...$$ on its own lines
9
+ # Inline math syntax: $$...$$ within text
10
+ #
11
+ # Examples:
12
+ # $$\lambda_\alpha > 5$$
13
+ # $$1 + 1$$
14
+ #
15
+ class Math < Base
16
+ attribute :content, :string
17
+ attribute :inline, :boolean, default: false
18
+
19
+ # Check if this is inline math
20
+ # @return [Boolean]
21
+ def inline?
22
+ inline == true
23
+ end
24
+
25
+ # Create an inline math element
26
+ # @param content [String] The math content
27
+ # @return [Math]
28
+ def self.inline(content)
29
+ new(content: content, inline: true)
30
+ end
31
+
32
+ # Create a block math element
33
+ # @param content [String] The math content
34
+ # @return [Math]
35
+ def self.block(content)
36
+ new(content: content, inline: false)
37
+ end
38
+
39
+ # Convert to Markdown
40
+ # @return [String]
41
+ def to_md
42
+ if inline?
43
+ "$$#{content}$$"
44
+ else
45
+ "$$\n#{content}\n$$"
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # Paragraph model representing a Markdown paragraph.
6
+ #
7
+ # @example Create a paragraph
8
+ # para = Coradoc::Markdown::Paragraph.new(text: "Hello World")
9
+ #
10
+ class Paragraph < Base
11
+ attribute :text, :string
12
+
13
+ # Mixed content (strings and inline model objects)
14
+ # @return [Array] mixed content array
15
+ attr_reader :children
16
+
17
+ def initialize(text: '', children: nil)
18
+ super()
19
+ @text = text
20
+ @children = children || []
21
+ end
22
+
23
+ def children=(value)
24
+ @children = value || []
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ module Coradoc
5
+ module Markdown
6
+ # Represents strikethrough text using GFM ~~ syntax.
7
+ #
8
+ # Example: ~~deleted text~~
9
+ #
10
+ class Strikethrough < Base
11
+ attribute :text, :string
12
+
13
+ def to_md
14
+ "~~#{text}~~"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # Strong model representing bold text (**text** or __text__).
6
+ #
7
+ class Strong < Base
8
+ attribute :text, :string
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # Table model representing a Markdown table.
6
+ #
7
+ class Table < Base
8
+ attribute :headers, :string, collection: true
9
+ attribute :rows, :string, collection: true, default: []
10
+ attribute :alignments, :string, collection: true # :left, :center, :right
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coradoc
4
+ module Markdown
5
+ # Text model representing plain text content.
6
+ #
7
+ class Text < Base
8
+ attribute :content, :string
9
+
10
+ def to_s
11
+ content
12
+ end
13
+ end
14
+ end
15
+ end