Code Monkey home page Code Monkey logo

asciidoctor / asciidoctor-extensions-lab Goto Github PK

View Code? Open in Web Editor NEW
104.0 18.0 101.0 336 KB

A lab for testing and demonstrating Asciidoctor extensions. Please do not use this code in production. If you want to use one of these extensions in your application, create a new project, import the code, and distribute it as a RubyGem. You can then request to make it a top-level project under the Asciidoctor organization.

License: Other

Ruby 66.64% CSS 31.60% HTML 0.20% JavaScript 1.55%

asciidoctor-extensions-lab's Introduction

Asciidoctor Extensions Lab

This repository is a lab for experimenting with Ruby-based Asciidoctor extensions using the Extensions API. Please do not use this code in production. The code is untested. It is also not packaged and distributed. The purpose of these examples is to demonstrate how extensions are set up, how to write them, and what they can do. The examples also offer patterns that can be reused when implementing your own extension.

In order to use the extensions in this repository, you need to clone the repository. Then, you need to pass the location of the extension you want to use to Asciidoctor using the -r CLI option or require it in your Ruby script if you are using the Asciidoctor API.

If you only want to test the extensions in this repository, skip ahead to Using an extension.

If you want to use one of the extensions from this lab in production, and perhaps develop it further, please import it into a new project and distribute it as a RubyGem. If you’re prepared to maintain it for the community, you can submit a request in the project chat to graduate it a top-level project in the Asciidoctor organization. When writing your own extension, we recommend that you study the extensions section in the Asciidoctor documentation.

Extension types

We have the following types of extensions in the lab:

  • Preprocessor - processes the AsciiDoc source before it is parsed

  • IncludeProcessor - intercepts the AsciiDoc include directive

  • TreeProcessor - processes the AsciiDoc document (AST) after block-level parsing is complete

  • Postprocessor - processes the converted output before it is written to the output stream (or disk)

  • DocinfoProcessor - contributes additional content to the header or footer of the output document

  • BlockProcessor - adds a custom delimited block

  • BlockMacroProcessor - adds a custom block macro

  • InlineMacroProcessor - adds a custom inline macro

The type of extension (e.g, -block-macro) is always used in the name of the extension registration file and directory to make it easy to distinguish. You can also look for examples using git grep. For example, to look for a BlockMacroProcessor, run the following command:

$ git grep BlockMacroProcessor lib/

You’ll get a result like this:

lib/gist-block-macro/extension.rb:class GistBlockMacro < Extensions::BlockMacroProcessor
lib/pass-block-macro/extension.rb:class PassBlockMacro < Extensions::BlockMacroProcessor
lib/tree-block-macro/extension.rb:class TreeBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor

Extension files

Each extension consists of several files:

  • A file that registers the extension (sometimes also contains the extension)

  • A file with the extension itself (when not defined in the registration file)

  • A file with sample AsciiDoc source to use to test the extension

  • Auxiliary assets needed by the extension

For example, the emoji-inline-macro extension has four files:

📎
The registration file (e.g., emoji-inline-macro.rb) goes in the lib directory whereas the remaining files go inside a directory whose base name matches the name of the registration file (e.g., emoji-inline-macro).

Extension catalog

The following extensions are available in the lab. When the registration of the extension is in a separate file from the extension code, you require the registration file.

AutoXrefTreeprocessor (registration & extension code)

Refers images, tables, listings, sections by their numbers.

BackToTopDocinfoProcessor (registration & extension code)

Adds a floating back to top button to the bottom right corner of the page.

ChartBlockMacro

Adds a chart block and block macro to AsciiDoc powered by c3js, chartist or chartjs. Replaced by Asciidoctor Chart.

ChromeInlineMacro (registration, extension code)

Adds an inline macro for linking to a chrome:// URI.

CopyToClipboardDocinfoProcessor (registration, extension code)

Adds a source toolbox with a copy to clipboard button to all source blocks.

CopyrightFooterPostprocessor (registration, extension code)

Adds a copyright to the document footer based on the value of the copyright attribute.

CustomAdmonitionBlock (registration, extension code)

Introduces a new admonition block type, complete with a custom icon.

DocstatInlineMacro (registration, extension code)

A macro that displays the word count and estimated reading time of the current document.

DumpAttributesBlockMacro (registration & extension code)

Dumps the document attributes as attribute entries in a source block.

EmojiInlineMacro (registration, extension code)

Adds an emoji inline macro for inserting emoji by name.

EnableSourcemapPreprocessor (registration & extension code)

Specifies sourcemap attribute for document.

ExternalHeaderAttributesPreprocessor (registration, extension code)

Reads additional AsciiDoc attributes from a YAML-based configuration file and adds them to the document header.

FoldLinesTreeProcessor (registration & extension code)

Replaces newlines (i.e., line feeds) in paragraphs with a single space.

FootnotesBlockMacro (registration, extension code)

Consumes the footnotes from the document catalog and puts them into a dedicated section.

FrontMatterPreprocessor (registration, extension code)

Emulates the built-in behavior of Asciidoctor to sweep away YAML front matter into the front-matter attribute.

GitMetadataInlineMacro (registration, extension code)

Provide information on references using a macro (e.g. commits, branches and tags).

GitMetadataPreprocessor (registration, extension code)

Provide information on the local git repository, e.g. the branch or tag name or the commit id.

GistBlockMacro (registration, extension code)

Adds a block macro to embed a gist into an AsciiDoc document.

GlobIncludeProcessor (registration, extension code)

Enhances the include directive to support a glob expression to include all matching files.

GoogleAnalyticsDocinfoProcessor (registration & extension code)

Adds the Google Analytics code for the account identified by the google-analytics-account attribute to the bottom of the HTML document.

HardbreaksPreprocessor (registration & extension code)

Adds hardbreaks to the end of all non-empty lines that aren’t section titles.

HighlightTreeprocessor (registration & extension code)

Highlights source blocks using the highlight command.

ImplicitApidocInlineMacro (registration & extension code)

Adds an inline macro for linking to the Javadoc of a class in the Java EE API.

ImplicitHeaderIncludeProcessor (registration, extension code)

Skips the implicit author line below the document title in included documents.

LicenseUrlDocinfoProcessor (registration & extension code)

Adds a link to the license specified by the license attribute to the document header.

LoremBlockMacro (registration & extension code)

Generates lorem ipsum text using the Middleman lorem extension. (Requires middleman >= 4.0.0).

ManInlineMacro (registration, extension code)

Adds an inline macro for linking to another man page (used in the Git documentation).

MathematicalTreeprocessor

Converts all latexmath blocks to SVG using the Mathematical library. Replaced by Asciidoctor Mathematical.

MarkdownLinkInlineMacro (registration & extension code)

Parses a Markdown-style link.

MentionsInlineMacro (registration & extension code)

Detects Twitter-style username mentions and converts them to links.

MultipageHtml5Converter (registration & extension code)

A converter that chunks the HTML5 output into multiple pages. This extension is merely a proof of concept. You can find a complete implementation of a multipage HTML converter at https://github.com/owenh000/asciidoctor-multipage.

MultirowTableHeaderTreeProcessor (registration & extension code)

Promotes additional rows from the table body to the table head(er). Number of header rows is controlled by the hrows attribute on the table block.

NestedOpenBlock (registration & extension code)

Allows open blocks to be nested by repurposing the example container as an open block.

NumberParagraphsTreeProcessor (registration, extension code)

Naively numbers paragraphs based on position.

PassBlockMacro (registration, extension code)

Adds a pass block macro to AsciiDoc.

PickInlineMacro (registration & extension code)

Adds an inline macro for selecting between two values based on the value of another attribute.

PullquoteInlineMacro (registration, extension code)

Adds an inline macro to pull a quote out of the flow and display it in a sidebar.

RubyAttributesPreprocessor (registration, extension code)

Makes information about the Ruby runtime available to the document by defining document attributes for all constants that begin with RUBY_ (e.g, ruby-version).

SectnumoffsetTreeprocessor (registration & extension code)

Increments all level-1 section numbers (and subsequently all subsections) by the value of the sectnumoffset attribute.

ShellSessionTreeProcessor (registration, extension code)

Detects a shell command and trailing output and styles it for display in HTML.

ShoutBlock (registration, extension code)

Converts all text inside a delimited block named shout to uppercase and adds trailing exclamation marks.

ShowCommentsPreprocessor (registration & extension code)

Converts line comments to visual elements (normally dropped).

SlimBlock (registration, extension code)

Passes the content in blocks named slim to the Slim template engine for processing.

StepsPostprocessor (registration, extension code)

Styles an ordered list as a procedure list.

TelInlineMacro (registration & extension code)

Adds an inline macro for linking to a tel: URI.

TermInlineMacro (registration & extension code)

Demonstrates how to convert an inline macro into a span of text with a role.

TexPreprocessor (registration, extension code)

Interprets tex markup embedded inside of AsciiDoc.

TextqlBlock (registration & extension code)

Adds a block for using textql to process data in an AsciiDoc document.

TreeBlockMacro (registration, extension code)

Adds a block macro to show the output of the tree command.

UndoReplacementsPostprocessor (registration & extension code)

Reverses the text replacements that are performed by Asciidoctor.

UriIncludeProcessor (registration, extension code)

Emulates the built-in behavior of Asciidoctor to include content from a URI.

ViewResultDocinfoProcessor (registration, extension code)

Adds an interactive toggle to block content marked as a view result.

WhitespaceIncludeProcessor (registration & extension code)

An include processor that substitutes tabs with spaces (naively) in included source code.

XmlEntityPostprocessor (registration, extension code)

Converts named entities to character entities so they can be resolved without the use of external entity declarations.

Using an extension

Before creating your own extensions, it would be wise to run one yourself. First, make sure Asciidoctor is installed:

$ gem install asciidoctor

Next, run the extension from the root directory of the project:

$ asciidoctor -r lib/emoji-inline-macro.rb lib/emoji-inline-macro/sample.adoc
# asciidoctor: FAILED: 'lib/emoji-inline-macro.rb' could not be loaded
# Use --trace for backtrace

Oops! We forgot to include the leading ./ when using the -r flag Let’s try again:

$ asciidoctor -r ./lib/emoji-inline-macro.rb lib/emoji-inline-macro/sample.adoc

All right, it ran! The output file, sample.html, was created in the same directory as the source file, sample.adoc.

The relevant bits of the input and output are shown below.

lib/emoji-inline-macro/sample.adoc
Faster than a emoji:turtle[1x]!

This is an example of how you can emoji:heart[lg] Asciidoctor and Twitter Emoji.
lib/emoji-inline-macro/sample.html
<div class="paragraph">
<p>Faster than a <i class="twa twa-1x twa-turtle"></i>!</p>
</div>
<div class="paragraph">
<p>This is an example of how you can <i class="twa twa-lg twa-heart"></i> Asciidoctor and Twitter Emoji.</p>
</div>
⚠️
Certain extensions require additional libraries. Please consult the extension’s registration file for details about what is required to use it.

Adding an extension

You can find examples of various ways to define an extension in the lib/shout-block.rb extension.

Shorthand (DSL)

If you’re creating a trivial extension, you can define the extension using the extension DSL directly in the registration file. Create a new file in the lib directory. Include the extension type in the name of the file so others are clear what type of extension it is.

lib/sample-block.rb
Asciidoctor::Extensions.register do
  block do
    named :sample
    on_context :open

    process do |parent, reader, attrs|
      create_paragraph parent, reader.lines, attrs
    end
  end
end

Formal

If you’re creating a more complex extension or want to enable reuse, you’re encouraged to move the extension code to the extension.rb inside a directory with the same base name as the registration file. In the case of a block, block macro or inline macro, this enables you to register the extension multiple times.

lib/sample-block.rb
RUBY_ENGINE == 'opal' ? (require 'sample-block/extension') : (require_relative 'sample-block/extension')

Asciidoctor::Extensions.register do
  block SampleBlock
end
lib/sample-block/extension.rb
class SampleBlock < Asciidoctor::Extensions::BlockProcessor
  use_dsl
  named :sample
  on_context :open

  def process parent, reader, attrs
    create_paragraph parent, reader.lines, attrs
  end
end

It’s customary to provide a sample AsciiDoc file named sample.adoc inside the extension subdirectory that others can use to try the extension. You should also add your extension to the Extension catalog section along with a short description of what it does.

Other extensions

See this list of official and community extensions for Asciidoctor.

Here are some other experimental extensions.

  • imagemap block processor - Adds an image with an imagemap using targets specified in the contents of the block. Note that this extension does not follow the standard use of block attrlists and is therefore considered to be experimental. However, it could be a useful starting point for someone interesting in creating one that is more conventional.

You may also be interested in these extensions which were submitted, but never merged:

Copyright © 2014-present The Asciidoctor Project. Free use of this software is granted under the terms of the MIT License.

See the LICENSE file for details.

asciidoctor-extensions-lab's People

Contributors

alterakey avatar atishay avatar bk2204 avatar bulletmark avatar culyun avatar danyill avatar edusantana avatar ggrossetie avatar liljenstolpe avatar lordofthejars avatar maxandersen avatar mojavelinux avatar nicorikken avatar nightscape avatar petk avatar smurfz87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asciidoctor-extensions-lab's Issues

showcomments-preprocessor seems broken with latest asciidoctor

Running:

asciidoctor -r ./lib/showcomments-preprocessor.rb lib/showcomments-preprocessor/sample.adoc

gives me:

/Users/max/code/asciidoctor-extensions-lab/lib/showcomments-preprocessor.rb:4:in `<top (required)>': uninitialized constant Extensions (NameError)
	from /Users/max/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Users/max/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Users/max/.rvm/gems/ruby-2.3.3/gems/asciidoctor-1.5.6.1/lib/asciidoctor/cli/options.rb:230:in `block in parse!'
	from /Users/max/.rvm/gems/ruby-2.3.3/gems/asciidoctor-1.5.6.1/lib/asciidoctor/cli/options.rb:228:in `each'
	from /Users/max/.rvm/gems/ruby-2.3.3/gems/asciidoctor-1.5.6.1/lib/asciidoctor/cli/options.rb:228:in `parse!'
	from /Users/max/.rvm/gems/ruby-2.3.3/gems/asciidoctor-1.5.6.1/lib/asciidoctor/cli/options.rb:33:in `parse!'
	from /Users/max/.rvm/gems/ruby-2.3.3/gems/asciidoctor-1.5.6.1/lib/asciidoctor/cli/invoker.rb:22:in `initialize'
	from /Users/max/.rvm/gems/ruby-2.3.3/gems/asciidoctor-1.5.6.1/bin/asciidoctor:12:in `new'
	from /Users/max/.rvm/gems/ruby-2.3.3/gems/asciidoctor-1.5.6.1/bin/asciidoctor:12:in `<top (required)>'
	from /Users/max/.rvm/gems/ruby-2.3.3/bin/asciidoctor:23:in `load'
	from /Users/max/.rvm/gems/ruby-2.3.3/bin/asciidoctor:23:in `<main>'
	from /Users/max/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `eval'
	from /Users/max/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `<main>'

Cross compile gist-block-macro

The current gist-block-macro extension is not cross compiling well with Opal.
I don't know the reason behind but when I replaced registry.document with @document everything work as expected.

Given that other extensions favor @document over registry.document I think it's a good idea to stick with @document (shorter).

Document how to create a new admonition type

I think it's an extension I need, but I'm not sure how to go about making one. Here's what I need:

I am converting a text book to various e-formats and the book has several in-text devices. Up till now I have been using the built-in admonitions and just created a new stylesheet to use different icons to match what I need. However, it seems to me that rather than subverting the existing admonitions it would be better to create new custom blocks for this project. For example, I need a block that looks and behaves exactly like an admonition except that it should be called thinkspot rather than tip, caution, warning, or note.

Can someone give me a step-by-step on what to do?

Thanks!

"Standard" way to overload assets path

When using extension(.js) in the chrome extension, assets are stored within the extension package and the URL is chrome-extension://<EXTENSION_ID>/.

I think it would be nice to have a standard way to overload assets path.

Create an extension to generate a changelog

The idea is to be able to generate a changelog:

We could even support multiple SCM. For instance, if we want to display the Git changelog of a project, between master and version 1.0.0:

changelog:git[master..v1.0.0]

Modify parsing options from an extension

I tried creating an extension that would generate HTML ready to be pasted into a Wordpress post in source form (minimal HTML).

For it to work without setting the --no-header-footer in addition to the -r flag I would have liked to set the :header_footer = false option directly when the extension is registered.

I've tried several ways and it didn't work. Including subclassing and overloading initialize and trying to access the @options field and add the option to it (but the hash is frozen).

I need guidance. Here's the code with attempts commented out: https://github.com/asciidoctor/asciidoctor-extensions-lab/compare/master...obilodeau:wordpress-extension?expand=1

Unit test extension for source blocks

It would be interested to demonstrate how to create an extension for AsciiDoc that ran through all the source listings and verified the expected output. This is an inside-out-approach from pulling snippets from a test suite. Different circumstances call for different approaches.

Since the extension has to run the assertions, it will likely be language-specific. We should focus on Ruby or JavaScript in the example.

Here's the inspiration for this extension (though it uses really quirky syntax which I'd like to improve on).

http://www.jspatterns.com/unit-testing-in-asciidoc/

Create summaries from distributed definitions

OK, couldn't find a better title... Here is what I want to do:
I am writing technical machine (not software :-) ) documentation using asciidoctor on atom. The machines are described by elements. With the element it is suitable to define the required maintenance work. Could be a small table, an admonition, ... whatever.

While for the writer it is suitable to have the maintenance described with the element, it is more suitable for the maintenance person to have a maintenance summary list at the end of the document.

I came up with tags and a self-including document, see code snippet below. Any better idea?

= Title

== Motor

Content not part of the maintenance tag

|===
| Element | Maintenance Instruction | Frequency

// tag::Maintenance[]
| icon:Maintenance[] <<Motor>> Oil | Change Motor Oil, use for salad | Daily
// end::Maintenance[]
|===

== Extruder

|===
| Element | Maintenance Instruction | Frequency

// tag::Maintenance[]
| icon:Maintenance[] <<Extruder>> Screw | Make nice & shiny | Before go to sleep
// end::Maintenance[]
|===


== Maintenance Summary

|===
| Element | Maintenance Instruction | Frequency

include::Source.adoc[tag=Maintenance]

|===

Conditional statements are not working when I use preprocessor extensions

Conditional statements are not working when I use 'mathematical-treeprocessor' extension.
The "hello world" string doesn't apear when using 'preprossor extension'.

:enable-string:

ifdef::enable-string[]
hello world!
endif::[]

Conditional statements are working well when I delete mathematical-preprocessor code on 'mathematical-treeprocessor.rb'.

Extensions.register do
  # if @document.basebackend? 'html'
  //inline_macro MathematicalInlineMacro
  treeprocessor MathematicalTreeprocessor
end

I've tested several other preprocessors, it's same on other preprocessors make same problem too.

Conditional statements which looks for CLI attributes works well.
Only conditional satements which looks for DOCUMENT attributes are not working.

RunKit Code Block Processor

RunKit is a tool to try Node.js in the browser. It is wired to Node package registry – npm.

capture d ecran 2017-03-05 a 19 17 33

I imagine something like this:

[source,javascript,runkit="nodeVersion:6"]
----
const lodash = require("lodash");

lodash.camelCase('get content');
----

becomes interactive as https://runkit.com/oncletom/58bc55b33cdd1a0013ae1a89 by pressing the Run in browser button (like the View Results extension).

<script src="https://embed.runkit.com"></script>
<script>
document.querySelectorAll('[data-runkit]').forEach(el => {
  RunKit.createNotebook({
    element: el,
    source: el.querySelector("code").textContent
  });
});
</script>

// ...

<pre class="javascript" data-runkit data-runkit-version="6"><code>
const lodash = require("lodash");

lodash.camelCase('get content');
</code></pre>

RunKit documentation is available here: https://runkit.com/docs/embed

cc @Mogztter

Create an extension to execute JavaScript code in the browser

This could be really useful when writing documentation for a JavaScript library.
The extension will search for JavaScript source code blocks and add a link/button "Run this code in your browser" to execute the code and print the result in the browser.

How to access command line params from Preprocessor

I am planning to write a preprocessor to parse attributes from a yaml file as described in 566. In order to maximize the use of the config file, I am planing to implement a theme feature from the config file, which contains common attributes (overidable) and theme specific attributes.
Example:

linkcss: true
copycss: true
stylesdir: styles
themes:
   bright:
      stylesheet: asciidoctor
      source-highlighter: highlight.js
      highlightjs-theme: atom
   dark:
      stylesheet: asciidoctor-dark
      source-highlighter: highlight.js
      highlightjs-theme: monokai

Then the cli command is asciidoctor --config-file=conf.yml --theme=dark -a stylesdir=new_style input.adoc.

The order of the attributes is cli > theme > common. It's easier to implement theme > common, but for cli > theme, config-file and theme, the preprocessor need to read the command params.

asciidoc-coalescer.rb ignores attributes in file

This is a very minor issue, since it's got such an easy workaround, but I'm reporting it anyway.

If I have a doc with conditional formatting based on ifdef::[], the script ignores the attributes set in the file. They have to be passed via the command line. I would expect the following file to give me the english version when passed through the script, but it just gives me blank output. If I do ruby asciidoc-coalescer.rb -a en file.ad, however, I get the correct output.

:en:

ifdef::en[]
== My Document
English version

include::[some-file-en.ad]
endif::en[]

ifdef::pt[]
== Meu Documento
Versão em portugûes

include::[some-file-pt.ad]
endif::pt[]

Create chart block extension

Add a block extension to demonstrate how to output a chart using the content of the block as the data. One idea is using chart.js or d3.js.

Align chart extension with AsciiDoc conventions

To be consistent with the <name>::<target>[<attributes>] convention, I think we should change the placement of arguments so the data is <target> and the chart type is the first positional attribute. I think chart type should default to "line" if not specified.

chart::sample.csv[line]

chart::sample.csv[bar]

chart::sample.csv[step]

chart::sample.csv[spline]

I think we should also support positional attributes for x and y label as well as size.

chart::<data-uri>[<type>,<x-label>,<y-label>,<width>,<height>]

We should also support a block form where the data is specified in a literal block:

[chart,line]
....
January,February,March,April,May,June,July
28,48,40,19,86,27,90
65,59,80,81,56,55,40
....

It will be necessary to register separate extensions for the block macro and block forms, but they can share common code.

mathoid-treeprocessor error in svg

Been trying to get a compilation path that will render a document with math in it across html, pdf, epub, and mobi. Managed to get mathoid-treeprocessor installed after some tinkering.

Using the sample .adoc file:

= _Precompiled_ Math!

[stem#equation1]
++++
"d"(bbp,bbq) = sqrt((p_1 - q_1)^2 + (p_2 - q_2)^2)
++++

and the command:

asciidoctor  -r asciidoctor-pdf -r ./lib/mathoid-treeprocessor  -b pdf test.adoc --trace

I get the following output:

asciidoctor: WARNING: could not embed image: /Volumes/SSD Disk/git Repos/test/equation1.svg; Duplicate attribute "xlink:href"
Line: 23
Position: 7155
Last 80 unconsumed characters:

The generated svg file is not an equation but text containing an error message "This page contains the following errors..."

Running phantomjs main.js with the query string http://localhost:16000/?q=x^2&type=asciimath generates a web page in the browser saying:

This page contains the following errors:

error on line 1 at column 1252: Attribute xlink:href redefined
Below is a rendering of the page up to the first error.

The page source is:

<svg xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-22 -915.1157009464328 932.0389244992066 953.2641499988939" style="width: 2.167ex; height: 2.167ex; vertical-align: -0.135ex; margin: 1px 0px; position: static;" xmlns="http://www.w3.org/2000/svg"><defs id="MathJax_SVG_glyphs"><path id="STIXWEBMAINI-78" stroke-width="10" d="M243 355l12 -57c70 107 107 143 151 143c24 0 41 -15 41 -37c0 -21 -14 -36 -34 -36c-19 0 -28 17 -52 17c-18 0 -54 -44 -98 -121c0 -7 2 -21 8 -45l32 -134c7 -28 16 -41 30 -41c13 0 24 10 47 40c9 12 13 18 21 28l15 -9c-58 -90 -84 -114 -122 -114 c-32 0 -47 18 -59 68l-29 119l-88 -119c-44 -59 -64 -68 -95 -68s-50 16 -50 42c0 20 14 36 34 36c9 0 19 -4 32 -11c10 -6 20 -9 26 -9c11 0 30 19 51 49l82 116l-28 124c-14 60 -21 68 -46 68c-8 0 -20 -2 -39 -7l-18 -5l-3 16l11 4c61 22 94 29 117 29 c25 0 37 -18 51 -86Z"></path><path id="STIXWEBMAIN-32" stroke-width="10" d="M474 137l-54 -137h-391v12l178 189c94 99 130 175 130 260c0 91 -54 141 -139 141c-72 0 -107 -32 -147 -130l-21 5c21 117 85 199 208 199c113 0 185 -77 185 -176c0 -79 -39 -154 -128 -248l-165 -176h234c42 0 63 11 96 67Z"></path></defs><g stroke="black" fill="black" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><use xlink:href="#STIXWEBMAINI-78" xlink:href="#STIXWEBMAINI-78"></use><use transform="scale(0.7071067811865476)" xlink:href="#STIXWEBMAIN-32" x="640" y="583" xlink:href="#STIXWEBMAIN-32"></use></g></svg>

Any ideas?

ChartBlockMacro weird output

Hi,

I want to build chart-block-macro, after build I'm getting only

/* Generated by Opal 0.6.3 */
(function($opal) {
  var $a, $b, TMP_1, self = $opal.top, $scope = $opal, nil = $opal.nil, $breaker = $opal.breaker, $slice = $opal.slice;

  self.$require_relative("chart-block-macro/extension");
  return ($a = ($b = $scope.Extensions).$register, $a._p = (TMP_1 = function(){var self = TMP_1._s || this, $a;

  if ((($a = self.$document()['$basebackend?']("html")) !== nil && (!$a._isBoolean || $a == true))) {
      return self.$block_macro($scope.ChartBlockMacro)
      } else {
      return nil
    }}, TMP_1._s = self, TMP_1), $a).call($b);
})(Opal);

What can be the reason?

Create text hyphenation extension

Create an extension that inserts shy hyphens into text by passing the text through a library such as text-hyphen. The result is that justified text can be hyphenated at logical locations so that the spread of words is more even.

The output will work with the existing styles in the default Asciidoctor stylesheet. Here's a screenshot that demonstrates how it would look:

image

Create DocinfoProcessor for embedding JavaScript files in HTML output

Create a DocinfoProcessor extension for embedding JavaScript files in generated HTML output.

For example:

:javascripts: myjavascript.js

Converts into :

<script type='text/javascript' src='myjavascript.js'></script>

The javascripts attribute can be a comma-separated list of paths. We may also want to specify the location of the JavaScript file explicitly.

:header_javascripts: ...
:footer_javascripts: ...

The default should probably be header.

Create extension to detect merge conflicts

Create an extension to detect merge conflicts in AsciiDoc source files.

With large commits, it's easy to miss some conflict and accidentally commit it. Example here:

http://gist.asciidoctor.org/?e4b59c5f6b0a85689859

When this happens in source code, the compiler or a test will normally tell you. If Asciidoctor could detect the pattern and tell you (aka fail the build), that would be great. This could likely be handled by a Preprocessor extension.

Simple Tree Gen

I want to add simple tree diagrams to a text. Is possible to add an easy tree generation feature.

E.g.

- level 1 (A)
-- child of level A (B)
---  child of B
-- 2nd child of A
- 2nd child of root

Rename registration files

It would be more verbose to rename files inside lib/*.rb to include registration in their names:

lib/chart-block-macro-registration.rb
lib/chrome-inline-macro-registration.rb
lib/copyright-footer-postprocessor-registration.rb
lib/emoji-inline-macro-registration.rb
(...)

It would avoid errors like #45.

Extension for Sign languages

Hi,

I'm trying to write a extension for placing videos from a Sign Language. It would be some thing like this:

libras.yaml:

"casa": https://www.youtube.com/watch?v=xjxjTMBoNjE

sample.adoc:

:sign-lang: libras

sign::casa[]

It would read casa from libras.yaml and translate to:

video::https://www.youtube.com/watch?v=xjxjTMBoNjE[]

It would be more complex, but this would be a start.

Can someone help me?

Here's what I have done so far:

  • I think it would be a subclasse of BlockMacroProcessor, like gist-block-macro
  • A made a copy of gist-block-macro and replace gist to sign:
(...)
class SignBlockMacro < Extensions::BlockMacroProcessor
  use_dsl

  named :sign
(...)

sample.adoc

= Sign Block Macro Extension

.Guard setup to live preview AsciiDoc output
sign::mojavelinux/5546622[]
  • And I run it with -r:
asciidoctor-extensions-lab$ asciidoctor --trace -r lib/sign-languages/extension.rb lib/sign-languages/sample.adoc  
/home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- lib/sign-languages/extension.rb (LoadError)
    from /home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

  • It didn't work. So I have tests gist alone:
asciidoctor-extensions-lab$ asciidoctor --trace -r lib/gist-block-macro/extension.rb lib/gist-block-macro/sample.adoc 
/home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- lib/gist-block-macro/extension.rb (LoadError)
    from /home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  • Since I don't know if gist is working, then I have tested an other BlockMacroProcessor extension, the TreeBlockMacro. I changed the sample file to directory of mine, and tested it:
asciidoctor-extensions-lab$ asciidoctor --trace -r lib/tree-block-macro/extension.rb lib/tree-block-macro/sample.adoc 
/home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- lib/tree-block-macro/extension.rb (LoadError)
    from /home/santana/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

Can someone guide me? What I am doing wrong?

Multipage html5 converter breaks ToC support

With the help of #56 and by removing the hardcoded noheader attribute I tried to add ToCs in the chunked html files to no avail.

It looks like the multipage-html5-converter extension breaks :toc: handling somehow.

Subsection offset - parent needed

Contents

  • PROBLEM
  • EXAMPLE
  • HTML Output
  • Code

@mojavelinux, could you take a look at the below?

PROBLEM: Add offsets for subsections

In the example below a modification to sectnumoffset-treeprocessor.rb is used to offset subsection
numbers in the first section that is processed. I would like to insert a parent section at the head
of the document and eliminate the text == Outer Test\n so that the first line of the
HTML output is

<h3 id="_inner_test_a">2.3. Inner Test A</h3>

Help is needed from the Ascii Doctor.

EXAMPLE:

require 'asciidoctor-latex'
source = "== Outer Test\n=== Inner Test A\n$a^2 = 1$\n\n=== Inner Test B\nfoo\n\n== Outer again\nho ho ho!\n\n=== Yikes!"

puts Asciidoctor.convert(source, backend: 'html5', attributes: 'sectnums sectnumoffset=1  subsectnumoffset=2')

HTML output:

[~/dev/asciidoctor-latex/work] ruby-2.2.2 $ ruby y.rb   
subsectnumoffset: 2
Insert parent section at 'head' of document with offset 1
<div class="sect1">
<h2 id="_outer_test">2. Outer Test</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_inner_test_a">2.3. Inner Test A</h3>
<div class="paragraph">
<p>\(a^2 = 1\)</p>
</div>
</div>
<div class="sect2">
<h3 id="_inner_test_b">2.4. Inner Test B</h3>
<div class="paragraph">
<p>foo</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_outer_again">3. Outer again</h2>
<div class="sectionbody">
<div class="paragraph">
<p>ho ho ho!</p>
</div>
<div class="sect2">
<h3 id="_yikes">3.1. Yikes!</h3>

</div>
</div>
</div>

CODE:

Extensions.register do
  # A treeprocessor that increments each level-1 section number by the value of
  # the `sectnumoffset` attribute.
  #
  # In addition, if `subsectnumoffset` is defined and greater than zero,
  # the numbers of subsections in the first section encountered will
  # be incremented by the offset.
  #
  # The numbers of all subsections will be
  # incremented automatically since those values are calculated dynamically.
  #
  # Run using:
  #
  # asciidoctor -r ./lib/sectnumoffset-treeprocessor.rb -a sectnums -a sectnumoffset=1 lib/sectnumoffset-treeprocessor/sample.adoc
  #
  #
  treeprocessor do
    process do |document|
      if (document.attr? 'sectnums') && (sectnumoffset = (document.attr 'sectnumoffset', 0).to_i) > 0
        subsectnumoffset = (document.attr 'subsectnumoffset', 0).to_i
        warn "subsectnumoffset: #{subsectnumoffset}".red
        section_count = 0
        if subsectnumoffset > 0
          warn "Insert parent section at 'head' of document with offset #{sectnumoffset}".cyan
        end
        ((document.find_by context: :section) || []).each do |sect|
          next unless sect.level <= 2
          if sect.level == 1
            section_count += 1
            sect.number += sectnumoffset
          elsif sect.level == 2 && section_count == 1
            sect.number += subsectnumoffset
          end
        end
      end
      nil
    end
  end
end

Create extension or add-on script that extracts revision history from git history

Create either an extension or an add-on script that extracts the revision history from the git history.

The idea is to only store the latest revision number and corresponding remark in the document itself. Whenever the revision number is changed, you commit the change. Then, you can get a full history of revision numbers and corresponding remarks by walking the git history and looking for when then revision number changes. Create a catalog, then output it to a temporary docinfo file. Finally, convert as normal with the docinfo enabled.

Use require when running with Opal

Example:

RUBY_ENGINE == 'opal' ? (require 'man-inline-macro/extension') : (require_relative 'chrome-inline-macro/extension')

We can revert this change as soon as Opal 0.7.0 is released.

Rendering dlists with multipage.rb

I'm using the multipage converter to create chunked output. I ran into some issues trying to get the following markup to render properly:

##### Example title

pipeline.<name>.example::

Example text
+
*Required.*
+
.Example
----
# pipeline configuration
pipeline.example.quorum = \
----

I'd only get the title of this in the output. I think this can be addressed by the reparenting function here: https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/multipage-html5-converter.rb#L60. I think it maybe sufficient to add something like:

      if block.context == :dlist
        block.parent = parent
      end

after the recursive call to reparent. Adding that I started getting the output that I expected. Not sure if this is the right approach.

Add links to navigate extensions in README

It's hard to navigate the repository because some extensions are defined an an extension.rb file and some are defined in the main extension file. Add links to each extension listed in the README to navigate to each of the following files:

  • registration
  • extension code
  • sample

In some case, the registration and extension code are the same file.

Add list of tables and list of figures

In many documents it is needed to have list of figures and list of tables right below table of contents. Would be good to have this feature in asciidoctor-pdf

How do we use these extensions?

Asciidoctor version 1.5.2 mentions, in the help, an option to require ruby modules before running

    -r, --require LIBRARY            require the specified library before executing the processor (using require)
                                     may be specified more than once

I guess this can be used to load these extensions from the command line but I can't find any documentation about this. Especially it's not mentioned either here or here.

Create a proper README for the extensions lab

We need a README for this repository that covers (at least) the following information:

  1. What extensions are available here
  2. How to load an extension from the extension lab

We should also cover how these extensions are organized to help people create new ones.

This is a follow-up from the question posed in #35.

Create lint extension

That way writers could ensure that theirs documents respect conventions and best practices. @mojavelinux I'm sure you already have a list of best practices ? 😄

Then it would be great to let users configure rules with a simple config file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.