Code Monkey home page Code Monkey logo

asciidoctor-include-ext's Introduction

Asciidoctor Include Extension

Build Status Test Coverage Codacy Code quality Gem Version Yard Docs

This project is a reimplementation of the Asciidoctor’s built-in (pre)processor for the include::[] directive in extensible and more clean way. It provides the same features, but you can easily adjust it or extend for your needs. For example, you can change how it loads included files or add another ways how to select portions of the document to include.

Why?

You may ask why I reimplemented something that is already in the Asciidoctor core.

Well… Code for decision if the include is allowed, parsing attributes for partial selection, reading the file to be included, filtering its content according to lines or tags attribute, handling errors… all of this is implemented directly in a single 210 lines long method Asciidoctor::Reader#preprocess_include_directive with really horrible perl-like spaghetti code. 🍝 💩

How can you adjust it or reuse outside of the Asciidoctor codebase? For example, what if you can’t read documents directly from file system? Then you’re out of luck. There’s no way how to do that without reimplementing this whole mess on your own (monkey-patching Kernel.open and File.file? is not a sensible option…).

I wrote this extension to allow implementing a complete support of include::[] directive in GitLab. And also to open doors for adding some custom selectors, e.g. selecting lines using regular expression in addition to ranges of line numbers and tags.

Installation

To install (or update to the latest version):

gem install asciidoctor-include-ext

or to install the latest development version:

gem install asciidoctor-include-ext --pre

Usage

Just require 'asciidoctor-include-ext'. If you invoke Asciidoctor from command-line, use option -r to load the extension:

asciidoctor -r asciidoctor-include-ext README.adoc

If you don’t want the extension to be automatically registered in Asciidoctor, don’t require asciidoctor-include-ext, but asciidoctor/include_ext/include_processor.

Important
Bundler automatically requires all the specified gems. To prevent it, use gem 'asciidoctor-include-ext', require: false.

License

This project is licensed under MIT License. For the full text of the license, see the LICENSE 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.