A Markdown shard for the Crystal programming language
リビジョン | 896e7a1f46f7395dadd84d785816683a843e6909 (tree) |
---|---|
日時 | 2023-10-26 12:18:37 |
作者 | supercell <stigma@disr...> |
コミッター | supercell |
Small style changes and documentation fixes
@@ -64,15 +64,18 @@ require "./extern/dart_uri" | ||
64 | 64 | # If you are only interested in rendering Markdown to HTML, please refer |
65 | 65 | # to the [README](../index.html) which explains the use of `Luce.to_html`. |
66 | 66 | # |
67 | -# The main entrypoint to the library is the `Document` which encapsulates the | |
68 | -# parsing process converting a Markdown text into a tree of `Node` (`Array(Node)`). | |
67 | +# The main entrypoint to the library is the `Document` which | |
68 | +# encapsulates the parsing process converting a Markdown text into | |
69 | +# a tree of `Node` (`Array(Node)`). | |
69 | 70 | # |
70 | -# Two main parsing mechanics are used: | |
71 | +# The two main parsing mechanics used are: | |
71 | 72 | # |
72 | -# - Blocks, representing top level elements like: headers, paragraphs, blockquotes, | |
73 | -# code blocks, ... implemented via `BlockSyntax` subclasses. | |
74 | -# - Inlines, representing chunks of test within a block with special meaning, like: | |
75 | -# links, emphasis, inlined code, ... implemented via `InlineSyntax` subclasses. | |
73 | +# - Blocks, representing top-level elements | |
74 | +# implemented via `BlockSyntax` subclasses, | |
75 | +# such as headers, paragraphs, blockquotes, and code blocks. | |
76 | +# - Inlines, representing chunks of test within a block with special meaning, | |
77 | +# implemented via `InlineSyntax` subclasses, | |
78 | +# such as links, emphasis, and inlined code. | |
76 | 79 | # |
77 | 80 | # Looking closely at `Document.new()` a few other concepts merit a mention: |
78 | 81 | # |
@@ -80,12 +83,13 @@ require "./extern/dart_uri" | ||
80 | 83 | # - `Resolver` which aid in resolving links and images. |
81 | 84 | # |
82 | 85 | # If you are looking at extending the library to support custom formatting |
83 | -# what you may want is to: | |
86 | +# what you might want is to: | |
84 | 87 | # |
85 | 88 | # - Implement your own `InlineSyntax` subclasses |
86 | 89 | # - Implement your own `BlockSyntax` subclasses |
87 | 90 | # - Instruct the library to use those by: |
88 | -# - Creating a new `ExtensionSet` from one of the existing flavors adding your syntaxes | |
91 | +# - Creating a new `ExtensionSet` from one of the existing flavors | |
92 | +# and adding your syntaxes. | |
89 | 93 | # - Passing your syntaxes to `Document` or `Luce.to_html` as parameters. |
90 | 94 | module Luce |
91 | 95 | VERSION = "0.4.0" |
@@ -21,7 +21,7 @@ module Luce | ||
21 | 21 | until parser.done? |
22 | 22 | is_blank_line = parser.current.is_blank_line? |
23 | 23 | break if is_blank_line && should_end?(parser) |
24 | - break if !is_blank_line && !child_lines.empty? && pattern.matches?(parser.current.content) != true | |
24 | + break if !is_blank_line && !child_lines.empty? && !pattern.matches?(parser.current.content) | |
25 | 25 | |
26 | 26 | child_lines << Line.new( |
27 | 27 | parser.current.content.dedent.text, |
@@ -56,7 +56,7 @@ module Luce | ||
56 | 56 | next |
57 | 57 | end |
58 | 58 | |
59 | - return pattern.matches?(next_line.content) == false | |
59 | + return !pattern.matches?(next_line.content) | |
60 | 60 | end |
61 | 61 | end |
62 | 62 | end |
@@ -71,7 +71,8 @@ module Luce | ||
71 | 71 | children.map { |e| Line.new(e) } |
72 | 72 | end |
73 | 73 | |
74 | - # Whether this line is one kind of block, if true footnotes block should end. | |
74 | + # Whether this line is any kind of block. | |
75 | + # If `true`, the footnote block should end. | |
75 | 76 | private def _is_block?(syntax_list : Array(BlockSyntax), line : String) : Bool |
76 | 77 | syntax_list.any?(&.pattern.matches?(line)) |
77 | 78 | end |
@@ -9,10 +9,12 @@ module Luce | ||
9 | 9 | class Document |
10 | 10 | getter link_references = Hash(String, LinkReference).new |
11 | 11 | |
12 | - # Footnote ref count, keys are case-sensitive and added by define syntax | |
12 | + # Footnote ref count, keys are case-sensitive and added by define syntax. | |
13 | 13 | getter footnote_references = Hash(String, Int32).new |
14 | 14 | |
15 | - # Footnotes label by appearing order, are case-sensitive and added by ref syntax | |
15 | + # Footnotes label by appearing order. | |
16 | + # | |
17 | + # They are case-sensitive and added by ref syntax. | |
16 | 18 | getter footnote_labels = [] of String |
17 | 19 | |
18 | 20 | getter link_resolver : Resolver? |
@@ -208,7 +210,8 @@ module Luce | ||
208 | 210 | Text.new("\u21a9"), |
209 | 211 | ] of Node) |
210 | 212 | end |
211 | - # Ignore GFM's attributes: <data-footnote-backref aria-label="Back to content">. | |
213 | + # Ignore GFM's attributes: | |
214 | + # <data-footnote-backref aria-label="Back to content">. | |
212 | 215 | ret.attributes["href"] = "#fnref-#{ref}#{suffix}" |
213 | 216 | ret.attributes["class"] = "footnote-backref" |
214 | 217 | ret |
@@ -5,10 +5,13 @@ | ||
5 | 5 | # |
6 | 6 | |
7 | 7 | module Luce |
8 | - # The spec of GFM about footnotes is [missing](https://github.com/github/cmark-gfm/issues/283#issuecomment-1378868725). | |
9 | - # For source code of cmark-gfm, See [noMatch] label of [handle_close_bracket] function in [master@c32ef78](https://github.com/github/cmark-gfm/blob/c32ef78/src/inlines.c#L1236). | |
8 | + # The spec of GFM about footnotes is | |
9 | + # [missing](https://github.com/github/cmark-gfm/issues/283#issuecomment-1378868725). | |
10 | + # For source code of cmark-gfm, See `noMatch` label of | |
11 | + # `handle_close_bracket` function in [master@c32ef78](https://github.com/github/cmark-gfm/blob/c32ef78/src/inlines.c#L1236). | |
10 | 12 | # A Rust implementation is also [available](https://github.com/wooorm/markdown-rs/blob/2498e31eecead798efc649502bbf5f86feaa94be/src/construct/gfm_label_start_footnote.rs). |
11 | - # Footnote shares the same syntax with `LinkSyntax`, but goes a different branch of handling close bracket. | |
13 | + # Footnote shares the same syntax with `LinkSyntax`, | |
14 | + # but have a different branch of handling close bracket. | |
12 | 15 | class FootnoteRefSyntax |
13 | 16 | private def self.footnote_label(key : String) : String? |
14 | 17 | return nil if key.empty? || key.codepoint_at(0) != Charcode::CARET |
@@ -42,7 +42,7 @@ module Luce | ||
42 | 42 | char != Charcode::VT && |
43 | 43 | char != Charcode::CR && |
44 | 44 | char != Charcode::FF && |
45 | - !(multiline == true && char == Charcode::LF) | |
45 | + !(multiline && char == Charcode::LF) | |
46 | 46 | return i |
47 | 47 | end |
48 | 48 |