Skip to content

Commit

Permalink
Fix Kramdown parser crash
Browse files Browse the repository at this point in the history
... by using GFM (GitHub-flavored Markdown) parser (`kramdown-parser-gfm`)
instead of the default one (`kramdown`).

The default one fails to produce an AST (Abstract Syntax Tree) when
there is no blank line before the line with the opening code fence.

Related:
 - gettalong/kramdown#530
 - Python-Markdown/markdown#807

Fixes: carpentries#543
  • Loading branch information
maxim-belkin committed Feb 15, 2021
1 parent d021e1f commit f419f9c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Install GitHub Pages, Bundler, and kramdown gems
run: |
gem install github-pages bundler kramdown
gem install github-pages bundler kramdown kramdown-parser-gfm
- name: Install Python modules
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- name: Install GitHub Pages, Bundler, and kramdown gems
run: |
gem install github-pages bundler kramdown
gem install github-pages bundler kramdown kramdown-parser-gfm
- name: Install Python modules
run: |
Expand Down
3 changes: 2 additions & 1 deletion bin/markdown_ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
# Use Kramdown parser to produce AST for Markdown document.

require 'kramdown'
require 'kramdown-parser-gfm'
require 'json'

markdown = $stdin.read
doc = Kramdown::Document.new(markdown)
doc = Kramdown::Document.new(markdown, input: 'GFM', hard_wrap: false)
tree = doc.to_hash_a_s_t
puts JSON.pretty_generate(tree)

0 comments on commit f419f9c

Please sign in to comment.