-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #261 use the new syntax highlighter API introduced in Asciid…
…octor 2.0.0
- Loading branch information
1 parent
862588a
commit 43ef818
Showing
16 changed files
with
455 additions
and
205 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// .source-rouge | ||
// Demonstration of source highlighting with Rouge | ||
// :include: //div[@class="slides"] | ||
// :header_footer: | ||
= Source Code with Rouge | ||
:icons: font | ||
:source-highlighter: rouge | ||
:rouge-style: monokai | ||
|
||
== Requirements | ||
|
||
WARNING: This will not work from Asciidoctor.js | ||
|
||
[NOTE] | ||
==== | ||
For this to work. You need to add: | ||
gem 'rouge' | ||
to your `Gemfile` and re-run: | ||
bundle install | ||
==== | ||
|
||
== Use the Source | ||
|
||
[source, rust] | ||
---- | ||
fn main() { | ||
println!("Hello World!"); | ||
} | ||
---- | ||
|
||
== Stretch the Source | ||
|
||
[source, rust, role="stretch"] | ||
---- | ||
fn main() { | ||
println!("Hello stretched World!"); | ||
} | ||
---- |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
if RUBY_ENGINE == 'opal' | ||
require 'asciidoctor-revealjs/converter' | ||
require 'asciidoctor-revealjs/version' | ||
require 'asciidoctor-revealjs/highlightjs' | ||
else | ||
require 'asciidoctor' unless defined? Asciidoctor::Converter | ||
require_relative 'asciidoctor-revealjs/converter' | ||
require_relative 'asciidoctor-revealjs/version' | ||
require_relative 'asciidoctor-revealjs/highlightjs' | ||
end |
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,41 @@ | ||
# frozen_string_literal: true | ||
module Asciidoctor | ||
module Revealjs | ||
module SyntaxHighlighter | ||
# Override the built-in highlight.js syntax highlighter | ||
class HighlightJsAdapter < Asciidoctor::SyntaxHighlighter::Base | ||
register_for 'highlightjs', 'highlight.js' | ||
|
||
def initialize *args | ||
super | ||
@name = @pre_class = 'highlightjs' | ||
end | ||
|
||
def format node, lang, opts | ||
super node, lang, (opts.merge transform: proc { |_, code| | ||
code['class'] = %(language-#{lang || 'none'} hljs) | ||
code['data-noescape'] = true | ||
}) | ||
end | ||
|
||
def docinfo? location | ||
location == :footer | ||
end | ||
|
||
def docinfo location, doc, opts | ||
if RUBY_ENGINE == 'opal' && JAVASCRIPT_PLATFORM == 'node' | ||
revealjsdir = (doc.attr :revealjsdir, 'node_modules/reveal.js') | ||
else | ||
revealjsdir = (doc.attr :revealjsdir, 'reveal.js') | ||
end | ||
if doc.attr? 'highlightjs-theme' | ||
theme_href = doc.attr 'highlightjs-theme' | ||
else | ||
theme_href = "#{revealjsdir}/lib/css/zenburn.css" | ||
end | ||
%(<link rel="stylesheet" href="#{theme_href}"#{opts[:self_closing_tag_slash]}>) | ||
end | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,35 +1,19 @@ | ||
- if title? | ||
.title=captioned_title | ||
- nowrap = !(@document.attr? :prewrap) || (option? 'nowrap') | ||
/ implicit listing blocks and source blocks are rendered as code | ||
/ explicit listing blocks stay listing | ||
- if @style == 'source' || (@style == 'listing' && attributes[1] != 'listing') | ||
- language = attr :language | ||
- code_class = language ? [language, "language-#{language}"] : nil | ||
- pre_class = ['highlight'] | ||
- pre_lang = nil | ||
- code_noescape = false | ||
- case document.attr 'source-highlighter' | ||
- when 'coderay' | ||
- pre_class = ['CodeRay'] | ||
- when 'pygments' | ||
- pre_class = ['pygments','highlight'] | ||
- when 'prettify' | ||
- pre_class = ['prettyprint'] | ||
- pre_class << 'linenums' if attr? :linenums | ||
- pre_class << language if language | ||
- pre_class << "language-#{language}" if language | ||
- code_class = nil | ||
- when 'html-pipeline' | ||
- pre_lang = language | ||
- pre_class = code_class = nil | ||
- nowrap = false | ||
- when 'highlightjs', 'highlight.js' | ||
- code_noescape=true | ||
- pre_class << 'nowrap' if nowrap | ||
- pre_class << 'listingblock' | ||
- pre_class << role if role | ||
pre class=pre_class lang=pre_lang id=@id | ||
code data-noescape=code_noescape class=code_class =content | ||
- nowrap = (option? 'nowrap') || !(document.attr? 'prewrap') | ||
- syntax_hl = document.syntax_highlighter | ||
- if @style == 'source' | ||
- lang = attr :language | ||
- if syntax_hl | ||
- doc_attrs = document.attributes | ||
- css_mode = (doc_attrs[%(#{syntax_hl.name}-css)] || :class).to_sym | ||
- style = doc_attrs[%(#{syntax_hl.name}-style)] | ||
- opts = syntax_hl.highlight? ? { css_mode: css_mode, style: style } : {} | ||
- opts[:nowrap] = nowrap | ||
- else | ||
- pre_open = %(<pre class="highlight#{nowrap ? ' nowrap' : ''}"><code#{lang ? %[ class="language-#{lang}" data-lang="#{lang}"] : ''}>) | ||
- pre_close = '</code></pre>' | ||
- else | ||
pre class=(nowrap ? 'nowrap' : nil) =content | ||
- pre_open = %(<pre#{nowrap ? ' class="nowrap"' : ''}>) | ||
- pre_close = '</pre>' | ||
- id_attribute = id ? %( id="#{id}") : '' | ||
- title_element = title? ? %(<div class="title">#{captioned_title}</div>\n) : '' | ||
=%(<div#{id_attribute} class="listingblock#{(role = self.role) ? " #{role}" : ''}">#{title_element}<div class="content">#{syntax_hl ? (syntax_hl.format self, lang, opts) : pre_open + (content || '') + pre_close}</div></div>) |
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.