Skip to content

Commit 403529a

Browse files
Merge pull request #97 from icyleaf/nobody/options
Refactor options
2 parents a10611c + c3641d4 commit 403529a

12 files changed

Lines changed: 107 additions & 82 deletions

File tree

.ameba.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Metrics/CyclomaticComplexity:
88
- src/markd/parsers/block.cr
99
- src/markd/renderer.cr
1010

11-
Naming/QueryBoolMethods:
12-
Enabled: false
13-
1411
Naming/BlockParameterName:
1512
Enabled: false
1613

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Markd.to_html(markdown, options)
5656
| safe | `Bool` | false | if **true**, raw HTML will not be passed through to HTML output (it will be replaced by comments) |
5757
| prettyprint | `Bool` | false | if **true**, code tags generated by code blocks will have a `prettyprint` class added to them, to be used by [Google code-prettify](https://github.com/google/code-prettify). |
5858
| gfm | `Bool` | false | **Partial support** |
59-
| autolink | `Bool` | false | if **true**, more autolinks are detected, like bare email addresses or http links. Requires `gfm` be set to `true` |
59+
| autolink | `Bool` | false | if **true**, more autolinks are detected, like bare email addresses or http links |
6060
| toc | `Bool` | false | **Not supported for now** |
6161
| base_url | `URI?` | nil | if not **nil**, relative URLs of links are resolved against this `URI`. It act's like HTML's `<base href="base_url">` in the context of a Markdown document. |
6262

spec/markd_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ describe_spec("fixtures/alert.txt", gfm: true)
2323
describe Markd do
2424
# Thanks Ryan Westlund <rlwestlund@gmail.com> feedback via email.
2525
it "should escape unsafe html" do
26-
raw = %Q{```"><script>window.location="https://footbar.com"</script>\n```}
27-
html = %Q{<pre><code class="language-&quot;&gt;&lt;script&gt;window.location=&quot;https://footbar.com&quot;&lt;/script&gt;"></code></pre>\n}
26+
raw = %Q(```"><script>window.location="https://footbar.com"</script>\n```)
27+
html = %Q(<pre><code class="language-&quot;&gt;&lt;script&gt;window.location=&quot;https://footbar.com&quot;&lt;/script&gt;"></code></pre>\n)
2828

2929
Markd.to_html(raw).should eq(html)
3030
end

src/markd/options.cr

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ require "uri"
33
module Markd
44
# Markdown rendering options.
55
class Options
6-
property time, gfm, toc
6+
# Render parsing cost time for reading the source, parsing blocks, and parsing inline.
7+
property? time : Bool
8+
9+
# Enables GitHub Flavored Markdown support.
10+
#
11+
# https://github.github.com/gfm/
12+
property? gfm : Bool
13+
14+
# Not supported for now.
15+
property? toc : Bool
716

817
# If `true`:
918
# - straight quotes will be made curly
@@ -12,41 +21,58 @@ module Markd
1221
# - `...` will be changed to ellipses
1322
property? smart : Bool
1423

15-
@[Deprecated("Use `#smart?` instead.")]
16-
getter smart
17-
1824
# If `true`, source position information for block-level elements
1925
# will be rendered in the `data-sourcepos` attribute (for HTML).
2026
property? source_pos : Bool
2127

22-
@[Deprecated("Use `#source_pos?` instead.")]
23-
getter source_pos
24-
2528
# If `true`, raw HTML will not be passed through to HTML output
2629
# (it will be replaced by comments).
2730
property? safe : Bool
2831

29-
@[Deprecated("Use `#safe?` instead.")]
30-
getter safe
31-
3232
# If `true`, code tags generated by code blocks will have a
3333
# prettyprint class added to them, to be used by
3434
# [Google code-prettify](https://github.com/google/code-prettify).
3535
property? prettyprint : Bool
3636

37-
@[Deprecated("Use `#prettyprint?` instead.")]
38-
getter prettyprint
39-
4037
# If `base_url` is not `nil`, it is used to resolve URLs of relative
4138
# links. It act's like HTML's `<base href="base_url">` in the context
4239
# of a Markdown document.
4340
property base_url : URI?
4441

45-
property emoji : Bool
42+
# Enables GFM emoji support.
43+
#
44+
# For example:
45+
#
46+
# ```
47+
# @octocat :+1: This PR looks great - it's ready to merge! :ship:
48+
# ```
49+
#
50+
# Becomes:
51+
#
52+
# ```
53+
# @octocat 👍 This PR looks great - it's ready to merge! 🚢
54+
# ```
55+
# https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#using-emojis
56+
property? emoji : Bool
4657

47-
property tagfilter : Bool
58+
# If `true`, the following HTML tags will be filtered when rendering HTML output:
59+
#
60+
# * `<title>`
61+
# * `<textarea>`
62+
# * `<style>`
63+
# * `<xmp>`
64+
# * `<iframe>`
65+
# * `<noembed>`
66+
# * `<noframes>`
67+
# * `<script>`
68+
# * `<plaintext>`
69+
#
70+
# All other HTML tags are left untouched.
71+
property? tagfilter : Bool
4872

49-
property autolink : Bool
73+
# If `true`, more autolinks will be detected.
74+
# Setting to `false` does not disable autolink support as a whole.
75+
property? autolink : Bool
5076

5177
def initialize(
5278
@time = false,
@@ -62,5 +88,25 @@ module Markd
6288
@base_url = nil,
6389
)
6490
end
91+
92+
# Deprecated
93+
94+
@[Deprecated("Use `#time?` instead.")]
95+
getter time
96+
97+
@[Deprecated("Use `#gfm?` instead.")]
98+
getter gfm
99+
100+
@[Deprecated("Use `#smart?` instead.")]
101+
getter smart
102+
103+
@[Deprecated("Use `#source_pos?` instead.")]
104+
getter source_pos
105+
106+
@[Deprecated("Use `#safe?` instead.")]
107+
getter safe
108+
109+
@[Deprecated("Use `#prettyprint?` instead.")]
110+
getter prettyprint
65111
end
66112
end

src/markd/parsers/block.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Markd::Parser
2626
getter line, current_line, blank, inline_lexer,
2727
indent, indented, next_nonspace, refmap
2828

29-
delegate gfm, tagfilter, to: @options
29+
delegate gfm?, tagfilter?, to: @options
3030

3131
def initialize(@options : Options)
3232
@inline_lexer = Inline.new(@options)
@@ -55,11 +55,11 @@ module Markd::Parser
5555
end
5656

5757
def parse(source : String)
58-
Utils.timer("block parsing", @options.time) do
58+
Utils.timer("block parsing", @options.time?) do
5959
parse_blocks(source)
6060
end
6161

62-
Utils.timer("inline parsing", @options.time) do
62+
Utils.timer("inline parsing", @options.time?) do
6363
process_inlines
6464
end
6565

0 commit comments

Comments
 (0)