forked from asciidoctor/asciidoctor-extensions-lab
-
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.
* https://asciidoctor.zulipchat.com/#narrow/stream/279642-users/topic/abbreviations.20with.20tooltips.20for.20both.20pdf.20and.20html * asciidoctor/asciidoctor#252 * asciidoctor/asciidoctor#2534 * riscv-admin/docs-sig#31
- Loading branch information
1 parent
42e366e
commit 3646a73
Showing
5 changed files
with
82 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
RUBY_ENGINE == 'opal' ? (require 'abbreviate-inline-macro/extension') : (require_relative 'abbreviate-inline-macro/extension') | ||
|
||
Asciidoctor::Extensions.register do | ||
if @document.backend == 'html5' || @document.backend == 'pdf' | ||
inline_macro AbbreviateInlineMacro | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' | ||
|
||
include Asciidoctor | ||
|
||
class AbbreviateInlineMacro < Extensions::InlineMacroProcessor | ||
use_dsl | ||
|
||
named :tla | ||
name_positional_attributes 'title' | ||
|
||
def process parent, target, attrs | ||
doc= parent.document | ||
doc.attributes['seen_abbreviations'] ||= {} | ||
seen_abbreviations = doc.attributes['seen_abbreviations'] | ||
full_form = attrs['title'] || 'Abbreviation' | ||
if seen_abbreviations.key?(target) && doc.backend == 'html5' | ||
create_inline parent, :quoted, %(<abbr title="#{full_form}">#{target}</abbr>), type: :unquoted | ||
else | ||
seen_abbreviations[target] = full_form | ||
create_inline parent, :quoted, %(#{full_form} (#{target})), type: :unquoted | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
== List of hiking acronyms | ||
|
||
Some popular hiking acronyms: | ||
|
||
* tla:JMT[John Muir Trail] | ||
* tla:AT[Appalachian Trail] | ||
* tla:PCT[Pacific Crest Trail] |
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 @@ | ||
= Abbreviation Inline Macro Extension | ||
:abbr-LNT: tla:LNT[Leave No Trace] | ||
|
||
== Directly using macro in source | ||
|
||
Climbed to Everest tla:ABC[Advanced Base Camp]! | ||
|
||
Everest tla:ABC[Advanced Base Camp] is 6340 meters elevation. | ||
|
||
include::sample-inc.adoc[] | ||
|
||
== Using document attributes | ||
|
||
{abbr-LNT} | ||
|
||
I say again, "{abbr-LNT}" | ||
|
||
|
||
== Todos | ||
|
||
features/questions to answer that would make this more useful: | ||
|
||
* better pdf support | ||
** currently just repeat every title of the abbreviation | ||
* generate a list of abbreviations section | ||
** this could then be linked to in pdf/html form | ||
* is there programmatic tooltip like functionality in pdf? | ||
|
||
== Running | ||
|
||
From repo top level dir: | ||
|
||
.generate html example: | ||
``` | ||
asciidoctor -r ./lib/abbreviate-inline-macro.rb lib/abbreviate-inline-macro/sample.adoc | ||
``` | ||
|
||
.generate pdf example: | ||
``` | ||
asciidoctor-pdf -r ./lib/abbreviate-inline-macro.rb lib/abbreviate-inline-macro/sample.adoc | ||
``` |