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
  • Loading branch information
maxim-belkin committed Feb 15, 2021
1 parent d021e1f commit 4cf17a5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 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
11 changes: 6 additions & 5 deletions bin/markdown_ast.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
# frozen-string-literal: true

# Use Kramdown parser to produce AST for Markdown document.

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

markdown = $stdin.read
doc = Kramdown::Document.new(markdown)
markdown = STDIN.read()
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 4cf17a5

Please sign in to comment.