Skip to content

Commit

Permalink
Merge pull request #179 from DannyBen/add/pandoc-renderer
Browse files Browse the repository at this point in the history
Add pandoc as an alternative renderer
  • Loading branch information
DannyBen authored Apr 18, 2024
2 parents a00bc1c + 6d517c3 commit 554ba21
Show file tree
Hide file tree
Showing 20 changed files with 514 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v4

- name: Install OS dependencies
run: sudo apt-get -y install libyaml-dev
run: sudo apt-get -y install libyaml-dev pandoc

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand Down
16 changes: 15 additions & 1 deletion Runfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,25 @@ action :css do |args|
end

help "Generate rouge CSS"
action :rouge do
action :'css-rouge' do
puts 'Saving app/styles/_rouge.scss'
exec 'bundle exec rougify style github > app/styles/_rouge.scss'
end

help "Generate pandoc CSS"
action :'css-pandoc' do
File.write 'tmp/pandoc-style.css', '$highlighting-css$'
sample = <<~CODE
```ruby
puts "hello"
```
CODE
File.write 'tmp/pandoc-dummy.md', sample

puts 'Saving app/styles/_pandoc_code.scss'
system 'pandoc tmp/pandoc-dummy.md --metadata title=dummy --highlight-style=pygments --template=tmp/pandoc-style.css > app/styles/_pandoc_code.scss'
end

usage "(server|s) [--sample]"
help "Run server with spec docroot or the sample docroot"
option "--sample, -s", "Use the 'sample' folder instead of the fixture"
Expand Down
209 changes: 203 additions & 6 deletions app/public/css/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions app/public/css/main.css.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/styles/_manifest.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
@import "line";
@import "list";
@import "nav";
@import "pandoc_code";
@import "rouge";
@import "scrollbar";
@import "source_link";
@import "search";
@import "source_link";
@import "table";
@import "typography";

Expand Down
63 changes: 63 additions & 0 deletions app/styles/_pandoc_code.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
32 changes: 6 additions & 26 deletions lib/madness/markdown_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ def text
end

def to_html
@to_html ||= Redcarpet::Markdown.new(redcarpet_renderer, redcarpet_options).render text
@to_html ||= renderer.render text
end

private

def renderer
@renderer ||= Rendering::Handler.new config.renderer
end

def parse_toc(input)
input.gsub '<!-- TOC -->', toc
end
Expand All @@ -50,36 +54,12 @@ def has_h1?(input)
lines[0].match(/^# \w+/) || (lines[1] && lines[0].match(/^\w+/) && lines[1].start_with?('='))
end

def redcarpet_options
@redcarpet_options ||= {
no_intra_emphasis: true,
autolink: true,
tables: true,
fenced_code_blocks: true,
strikethrough: true,
space_after_headers: true,
superscript: true,
underline: true,
highlight: true,
quote: false,
footnotes: true,
}
end

def redcarpet_renderer
redcarpet_handler.new with_toc_data: true
end

def redcarpet_handler
config.highlighter ? HighlightRenderer : Redcarpet::Render::HTML
end

def toc
@toc ||= toc_handler.markdown
end

def toc_handler
@toc_handler ||= Madness::InlineTableOfContents.new markdown
@toc_handler ||= InlineTableOfContents.new markdown
end
end
end
Loading

0 comments on commit 554ba21

Please sign in to comment.