Project

md-noko

0.0
No release in over 3 years
Low commit activity in last 3 years
This is a simple module that encapsulates a set of desirable manipulations to the (X)HTML output of Redcarpet, producing a Nokogiri::XML::Document which is amenable to further manipulation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0
~> 3.0

Runtime

~> 3.4.0
~> 0.1.5
 Project Readme

MD::Noko: in goes Markdown, out comes Nokogiri

Synopsis

require 'md-noko'

mdnk = MD::Noko.new
doc  = mdnk.ingest File.open('lolwut.md')

# or

doc  = mdnk.ingest <<EOT
# Hi

Markdown here!

![lulz](meme.jpeg)

EOT

# doc is a Nokogiri::XML::Document

Description

This is a simple module that encapsulates a set of desirable manipulations to the (X)HTML output of Redcarpet. It exposes (for now) a single method, ingest, which returns a Nokogiri::XML::Document, for further manipulation. In particular, this module:

  • Adds HTML preamble to produce a valid document,
  • Creates a <base href=""/> element which you can pass a URL,
  • Creates a hierarchy of <section> elements and places headings and content inside,
  • If the document contains exactly one <h1> which is the very first thing in the file, it is copied into the <title>, and removed from the document body if determined to be redundant (i.e. unless it contains markup elements and not strictly text),
  • A <blockquote> element containing exactly one nested <blockquote> element is converted into a single <aside role="note">,
  • Images on their own paragraph are transformed into a <figure>,
  • Text nodes not descendants of <pre> are whitespace-normalized and indentation is repaired.

The embedded Redcarpet::Markdown instance has the following flags set:

  • :tables
  • :fenced_code_blocks
  • :quote
  • :highlight

These are currently not exposed.

Installation

The usual:

$ gem install md-noko

Or, download it off rubygems.org.

Contributing

Bug reports and pull requests are welcome at the GitHub repository.

Copyright & License

©2018 Dorian Taylor

This software is provided under the Apache License, 2.0.