forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[doc] Switch parser to kramdown, normalize Headings
The switch to kramdown is necessary because I want to add tabs in the documentation for code examples and Redcarpet does not allow markup inside divs. Before, some doc pages had "#" headings as toplevel headings while others had "##" (which is the same as --- underlined headings). Now we user level 2 everywhere. The page title is still a h1 heading.
- Loading branch information
Showing
31 changed files
with
1,210 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# We define the an additional option for the kramdown parser to look for | ||
module Kramdown | ||
module Options | ||
define(:kramdown_default_lang, Symbol, nil, <<EOF) | ||
Sets the default language for highlighting code blocks | ||
If no language is set for a code block, the default language is used | ||
instead. The value has to be one of the languages supported by pygments | ||
or nil if no default language should be used. | ||
Default: nil | ||
Used by: PygmentsHtml converter | ||
EOF | ||
end | ||
end | ||
|
||
# This class is a plugin for kramdown, to make it use pygments instead of coderay | ||
# It has nothing to do with Jekyll, it is simply used by the custom converter below | ||
module Kramdown | ||
module Converter | ||
class PygmentsHtml < Html | ||
|
||
begin | ||
require 'pygments' | ||
rescue LoadError | ||
STDERR.puts 'You are missing a library required for syntax highlighting. Please run:' | ||
STDERR.puts ' $ [sudo] gem install pygments' | ||
raise FatalException.new("Missing dependency: Pygments") | ||
end | ||
|
||
def convert_codeblock(el, indent) | ||
attr = el.attr.dup | ||
lang = extract_code_language!(attr) || @options[:kramdown_default_lang] | ||
code = pygmentize(el.value, lang) | ||
code_attr = {} | ||
code_attr['class'] = "language-#{lang}" if lang | ||
"#{' '*indent}<div class=\"highlight\"><pre#{html_attributes(attr)}><code#{html_attributes(code_attr)}>#{code}</code></pre></div>\n" | ||
end | ||
|
||
def convert_codespan(el, indent) | ||
attr = el.attr.dup | ||
lang = extract_code_language!(attr) || @options[:kramdown_default_lang] | ||
code = pygmentize(el.value, lang) | ||
if lang | ||
attr['class'] = "highlight" | ||
if attr.has_key?('class') | ||
attr['class'] += " language-#{lang}" | ||
else | ||
attr['class'] = "language-#{lang}" | ||
end | ||
end | ||
"<code#{html_attributes(attr)}>#{code}</code>" | ||
end | ||
|
||
def pygmentize(code, lang) | ||
if lang | ||
Pygments.highlight(code, | ||
:lexer => lang, | ||
:options => { :startinline => true, :encoding => 'utf-8', :nowrap => true }) | ||
else | ||
escape_html(code) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
# This class is the actual custom Jekyll converter. | ||
class Jekyll::Converters::Markdown::KramdownPygments | ||
|
||
def initialize(config) | ||
require 'kramdown' | ||
@config = config | ||
rescue LoadError | ||
STDERR.puts 'You are missing a library required for Markdown. Please run:' | ||
STDERR.puts ' $ [sudo] gem install kramdown' | ||
raise FatalException.new("Missing dependency: kramdown") | ||
end | ||
|
||
def convert(content) | ||
html = Kramdown::Document.new(content, { | ||
:auto_ids => @config['kramdown']['auto_ids'], | ||
:footnote_nr => @config['kramdown']['footnote_nr'], | ||
:entity_output => @config['kramdown']['entity_output'], | ||
:toc_levels => @config['kramdown']['toc_levels'], | ||
:smart_quotes => @config['kramdown']['smart_quotes'], | ||
:kramdown_default_lang => @config['kramdown']['default_lang'], | ||
:input => @config['kramdown']['input'] | ||
}).to_pygments_html | ||
return html; | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.