Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .ameba.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ Metrics/CyclomaticComplexity:
- src/markd/parsers/block.cr
- src/markd/renderer.cr

Naming/QueryBoolMethods:
Enabled: false

Naming/BlockParameterName:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Markd.to_html(markdown, options)
| safe | `Bool` | false | if **true**, raw HTML will not be passed through to HTML output (it will be replaced by comments) |
| 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). |
| gfm | `Bool` | false | **Partial support** |
| autolink | `Bool` | false | if **true**, more autolinks are detected, like bare email addresses or http links. Requires `gfm` be set to `true` |
| autolink | `Bool` | false | if **true**, more autolinks are detected, like bare email addresses or http links |
| toc | `Bool` | false | **Not supported for now** |
| 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. |

Expand Down
4 changes: 2 additions & 2 deletions spec/markd_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe_spec("fixtures/alert.txt", gfm: true)
describe Markd do
# Thanks Ryan Westlund <rlwestlund@gmail.com> feedback via email.
it "should escape unsafe html" do
raw = %Q{```"><script>window.location="https://footbar.com"</script>\n```}
html = %Q{<pre><code class="language-&quot;&gt;&lt;script&gt;window.location=&quot;https://footbar.com&quot;&lt;/script&gt;"></code></pre>\n}
raw = %Q(```"><script>window.location="https://footbar.com"</script>\n```)
html = %Q(<pre><code class="language-&quot;&gt;&lt;script&gt;window.location=&quot;https://footbar.com&quot;&lt;/script&gt;"></code></pre>\n)

Markd.to_html(raw).should eq(html)
end
Expand Down
78 changes: 62 additions & 16 deletions src/markd/options.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ require "uri"
module Markd
# Markdown rendering options.
class Options
property time, gfm, toc
# Render parsing cost time for reading the source, parsing blocks, and parsing inline.
property? time : Bool

# Enables GitHub Flavored Markdown support.
#
# https://github.github.com/gfm/
property? gfm : Bool

# Not supported for now.
property? toc : Bool

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

@[Deprecated("Use `#smart?` instead.")]
getter smart

# If `true`, source position information for block-level elements
# will be rendered in the `data-sourcepos` attribute (for HTML).
property? source_pos : Bool

@[Deprecated("Use `#source_pos?` instead.")]
getter source_pos

# If `true`, raw HTML will not be passed through to HTML output
# (it will be replaced by comments).
property? safe : Bool

@[Deprecated("Use `#safe?` instead.")]
getter safe

# 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).
property? prettyprint : Bool

@[Deprecated("Use `#prettyprint?` instead.")]
getter prettyprint

# If `base_url` is not `nil`, it is used to resolve URLs of relative
# links. It act's like HTML's `<base href="base_url">` in the context
# of a Markdown document.
property base_url : URI?

property emoji : Bool
# Enables GFM emoji support.
#
# For example:
#
# ```
# @octocat :+1: This PR looks great - it's ready to merge! :ship:
# ```
#
# Becomes:
#
# ```
# @octocat 👍 This PR looks great - it's ready to merge! 🚢
# ```
# 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
property? emoji : Bool

property tagfilter : Bool
# If `true`, the following HTML tags will be filtered when rendering HTML output:
#
# * `<title>`
# * `<textarea>`
# * `<style>`
# * `<xmp>`
# * `<iframe>`
# * `<noembed>`
# * `<noframes>`
# * `<script>`
# * `<plaintext>`
#
# All other HTML tags are left untouched.
property? tagfilter : Bool

property autolink : Bool
# If `true`, more autolinks will be detected.
# Setting to `false` does not disable autolink support as a whole.
property? autolink : Bool

def initialize(
@time = false,
Expand All @@ -62,5 +88,25 @@ module Markd
@base_url = nil,
)
end

# Deprecated

@[Deprecated("Use `#time?` instead.")]
getter time

@[Deprecated("Use `#gfm?` instead.")]
getter gfm

@[Deprecated("Use `#smart?` instead.")]
getter smart

@[Deprecated("Use `#source_pos?` instead.")]
getter source_pos

@[Deprecated("Use `#safe?` instead.")]
getter safe

@[Deprecated("Use `#prettyprint?` instead.")]
getter prettyprint
end
end
6 changes: 3 additions & 3 deletions src/markd/parsers/block.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Markd::Parser
getter line, current_line, blank, inline_lexer,
indent, indented, next_nonspace, refmap

delegate gfm, tagfilter, to: @options
delegate gfm?, tagfilter?, to: @options

def initialize(@options : Options)
@inline_lexer = Inline.new(@options)
Expand Down Expand Up @@ -55,11 +55,11 @@ module Markd::Parser
end

def parse(source : String)
Utils.timer("block parsing", @options.time) do
Utils.timer("block parsing", @options.time?) do
parse_blocks(source)
end

Utils.timer("inline parsing", @options.time) do
Utils.timer("inline parsing", @options.time?) do
process_inlines
end

Expand Down
Loading