Code Monkey home page Code Monkey logo

kramdown-asciidoc's Introduction

Kramdown AsciiDoc (Markdown to AsciiDoc)

Gem Version Build Status (GitHub Actions)

Kramdown AsciiDoc (gem: kramdown-asciidoc, command: kramdoc) is a kramdown extension for converting Markdown documents to AsciiDoc. Notably, the converter generates modern AsciiDoc syntax suitable for use with Asciidoctor.

Prerequisites

To install and run Kramdown AsciiDoc, you need Ruby 2.3 or better installed and a few RubyGems (aka gems). The instructions for installing the gems is covered in the next section.

To check whether you have Ruby installed, and which version, run the following command:

$ ruby -v

If Ruby is not installed, you can install it using RVM (or, if you prefer, the package manager for your system). We generally recommend using RVM because it allows you to install gems without requiring elevated privileges or messing with system libraries.

Installation

Kramdown AsciiDoc is published to RubyGems.org as a gem named kramdown-asciidoc.

You can install the latest version of the gem using the following command:

$ gem install kramdown-asciidoc

Installing this gem makes the kramdoc command available on your $PATH.

💡
To test a feature that’s not yet released, you can run the application from source.

Usage

To convert a Markdown file to AsciiDoc using Kramdown AsciiDoc, pass the name of the file to the kramdoc command as follows:

$ kramdoc sample.md

By default, the kramdoc command automatically creates the output file sample.adoc in the same folder as the input file. This path is calculated by removing the Markdown file extension, .md, and replacing it with the AsciiDoc file extension, .adoc.

📎
The converter assumes the input uses the GitHub-flavor Markdown (GFM) syntax.

If you want to direct the output to a different file, pass the name of that file to the kramdoc command using the -o option as follows:

$ kramdoc -o result.adoc sample.md

To direct the output to the console (i.e., STDOUT) instead of a file, use the special value - as follows:

$ kramdoc -o - sample.md

To see all the options the kramdoc command accepts, pass the -h option to the kramdoc command as follows:

$ kramdoc -h

For example, you can inject attributes (key/value pairs) into the header of the AsciiDoc output document using the -a option.

$ kramdoc -a product-name="ACME Cloud" -a hide-url-scheme sample.md

Another use for attributes is setting the shared images directory, which is covered in the next section.

Configure shared images directory

If the images in the source document share a common directory prefix, such as images/, you can configure the converter to extract that prefix, optionally promoting it to the document header.

Let’s assume you want to convert the following Markdown source:

# Document Title

![Octocat](images/octocat.png)

You can extract the images/ prefix from the image reference and promote this value to the header of the output document by setting the imagesdir attribute:

$ kramdoc -a imagesdir=images sample.md

Setting this attribute will produce the following document:

= Document Title
:imagesdir: images

image::octocat.png[Octocat]

If you want the images/ prefix to be removed altogether and not added to the document header (i.e., an implied prefix), set the --imagesdir option instead:

$ kramdoc --imagesdir=images sample.md

Setting this option will produce the following document:

= Document Title

image::octocat.png[Octocat]

In this scenario, you may need to pass the imagesdir attribute to the AsciiDoc processor when converting the output document so the image is resolved, depending on where the image is stored.

Auto-generate IDs

You can configure kramdoc to automatically generate explicit IDs for each section title (aka heading) that doesn’t already have an ID assigned to it (in the Markdown source). To do so, simply enable the --auto-ids flag:

$ kramdoc --auto-ids sample.md

By default, kramdoc does not add a prefix to the generated ID and uses - as the separator / replacement character. You can change these values using the --auto-id-prefix and --auto-id-separator options, respectively:

$ kramdoc --auto-ids --auto-id-prefix=_ --auto-id-separator=_ sample.md

Since the AsciiDoc processor generates an ID for any section title that doesn’t have one by default, you may decide you want to drop any ID which matches its auto-generated value. You can enable this behavior by adding the --lazy-ids flag:

$ kramdoc --lazy-ids sample.md

The catch is that kramdown/kramdoc and AsciiDoc don’t use the same prefix and separator when generating IDs. So it’s necessary to sync them. The simplest way is to set the --auto-id-prefix and --auto-id-separator values to match those used by AsciiDoc.

$ kramdoc --lazy-ids --auto-id-prefix=_ --auto-id-separator=_ sample.md

If these values do not match the defaults in AsciiDoc, the idprefix and/or idseparator attributes will be assigned explicitly in the generated document.

API

In additional to the command-line interface, Kramdown AsciiDoc also provides a porcelain API (see API docs). We use the term “porcelain” because the API hides the details of registering the converter, preprocessing the Markdown document, parsing the document with kramdown, and calling the converter method to transform the parse tree to AsciiDoc.

The API consists of two static methods in the Kramdoc module:

  • Kramdoc.convert(source, opts) - convert a Markdown string or IO object to AsciiDoc

  • Kramdoc.convert_file(file, opts) - convert a Markdown file object or path to AsciiDoc

📎
Kramdoc is a shorthand for Kramdown::AsciiDoc to align with the name of the CLI.

Both API methods accept the source as the first argument and an options hash as the second.

To convert a Markdown file to AsciiDoc using the Kramdown AsciiDoc API, pass the name of the file to the Kramdoc.convert_file method as follows:

require 'kramdown-asciidoc'

Kramdoc.convert_file 'sample.md'

Like the command-line, Kramdoc.convert_file converts the Markdown file to an adjacent AsciiDoc file calculated by removing the Markdown file extension, .md, and replacing it with the AsciiDoc file extension, .adoc.

If you want to direct the output to a different file, pass the name of that file to the Kramdoc.convert_file method using the :to option as follows:

require 'kramdown-asciidoc'

Kramdoc.convert_file 'sample.md', to: 'result.adoc'

To convert a Markdown string to an AsciiDoc string using the Kramdown AsciiDoc API, pass the string to the Kramdoc.convert method as follows:

require 'kramdown-asciidoc'

markdown = <<~EOS
# Document Title

Hello, world!
EOS

asciidoc = Kramdoc.convert markdown

If you want to direct the output to a file, pass the name of that file to the Kramdoc.convert method using the :to option as follows:

Kramdoc.convert markdown, to: 'result.adoc'

The input string is automatically converted to UTF-8.

For more information about the API, refer to the API documentation.

Development

To help develop Kramdown AsciiDoc, or to simply test-drive the development version, you need to retrieve the source from GitHub. Follow the instructions below to learn how to clone the source and run the application from source (i.e., your clone).

Retrieve the source code

Simply copy the GitHub repository URL and pass it to the git clone command:

$ git clone https://github.com/asciidoctor/kramdown-asciidoc

Next, switch to the project directory:

$ cd kramdown-asciidoc

Prepare RVM (optional)

We recommend using RVM when developing applications with Ruby. We like RVM because it keeps the dependencies required by the project isolated from the rest of your system. Follow the installation instructions on the RVM site to setup RVM and install Ruby.

Once you have RVM setup, switch to the RVM-managed version of Ruby recommended by the project using this command:

$ rvm use

The recommended version of Ruby is defined in the .ruby-version file at the root of the project.

Install the dependencies

The dependencies needed to use Kramdown AsciiDoc are defined in the Gemfile at the root of the project. You’ll use Bundler to install these dependencies.

To check if you have Bundler available, use the bundle command to query the version installed:

$ bundle --version

If Bundler is not installed, use the gem command to install it.

$ gem install bundler

Then, use the bundle command to install the project dependencies under the project directory:

$ bundle --path=.bundle/gems
📎
You must invoke bundle from the project’s root directory so it can locate the Gemfile.

Run the tests

The test suite is located in the spec directory. The tests are all based on RSpec.

Most specs are scenarios, located under the spec/scenarios directory. Each scenario consists of a Markdown file that ends in .md (the given), an AsciiDoc file that ends in .adoc (the then), and an optional options file that ends in .opts. The test converts the Markdown to AsciiDoc (the when) and validates the result against what’s expected. The specification name of each scenario is derived from the directory name.

You can run all of the tests using Rake:

$ bundle exec rake

For more fine-grained control, you can also run the tests directly using RSpec:

$ bundle exec rspec

To run all the scenarios, point RSpec at the spec file:

$ bundle exec rspec spec/scenario_spec.rb

Run individual tests

If you only want to run a single test, or a group of tests, you can do so by tagging the test cases, then filtering the test run using that tag.

Start by adding the wip tag to one or more specifications:

it 'should do something new', wip: true do
  expect(true).to be true
end

Next, run RSpec with the wip flag enabled:

$ bundle exec rspec -t wip

RSpec will only run the specifications that contain this flag.

You can also filter tests by keyword. Let’s assume we want to run all the tests that have wrap in the description. Run RSpec with the example filter:

$ bundle exec rspec -e wrap

RSpec will only run the specifications that have a description containing the text wrap.

Generate code coverage

To generate a code coverage report when running tests using simplecov, set the COVERAGE environment variable as follows when running the tests:

$ COVERAGE=true bundle exec rake

You’ll see a total coverage score as well as a link to the HTML report in the output. The HTML report helps you understand which lines and branches were missed, if any.

Despite being fast, the downside of using simplecov is that it misses branches. You can use deep-cover to generate a more thorough report. To do so, set the COVERAGE environment variable as follows when running the tests:

$ COVERAGE=deep bundle exec rake

You’ll see a total coverage score, a detailed coverage report, and a link to HTML report in the output. The HTML report helps you understand which lines and branches were missed, if any.

As an alternative to deep cover’s native HTML reporter, you can also use istanbul / nyc. First, you’ll need to have the nyc command available on your system:

$ npm install -g nyc

or

$ yarn global add nyc

Next, in addition to the COVERAGE environment variable, also set the DEEP_COVER_REPORTER environment variable as follows when running the tests:

$ COVERAGE=deep DEEP_COVER_REPORTER=istanbul bundle exec rake

You’ll see a total coverage score, a detailed coverage report, and a link to HTML report in the output. The HTML report helps you understand which lines and branches were missed, if any.

Usage

When running the kramdoc command from source, you must prefix the command with bundle exec:

$ bundle exec kramdoc sample.md

To avoid having to do this, or make the kramdoc command available from anywhere, you need to build the development gem and install it.

Alternatives

Authors

Kramdown AsciiDoc was written by Dan Allen.

Copyright © 2016-2021 OpenDevise Inc. and the individual contributors to Kramdown AsciiDoc. Free use of this software is granted under the terms of the MIT License.

See the LICENSE file for details.

kramdown-asciidoc's People

Contributors

archiloque avatar mojavelinux 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

kramdown-asciidoc's Issues

Integrate deep-cover to get more accurate code coverage

The standard coverage in Ruby does not analyzes code branches and misses certain conditionals such as case statements. Integrate the deep-cover gem into the test suite to get more accurate code coverage reports.

By default, the deep-cover gem introduces a lot of dependencies. I've prepared a branch of the project named no-cli (based on the 0.5.2 release) that removes the CLI and trims down the dependencies.

Add option to control line wrapping

Add an option to the API named :wrap to control how lines are wrapped. The converter should support three options initially:

  • :none - remove line wraps
  • :preserve - keep line wraps as they are in the original source
  • :ventilate - remove line wraps and add line breaks between sentences

We can then consider adding a custom wrap width in the future.

Add a preprocessor pipeline

Instead of hard-coding preprocessor functions (like extract_front_matter and replace_toc) in the CLI, introduce a preprocessing pipeline and register these built-in functions with that pipeline. This change will make the converter more flexible and easier to test.

JS version

I built a quick and dirty Markdown to Asciidoctor converter for one-off documents that can be quickly converted in the browser. It uses a very naive series of regexes to do the conversion rather than trying to do anything fancy (which is actually just enough to cover most of the basic features of Markdown), but it would obviously be better if it were possible to use kramdown-asciidoc as a backend instead. Would it be feasible to do something similar to asciidoctor.js and use Opal for example to turn this into a JS library?

Allow auto-generated ID prefix to be set

Allow the auto-generated ID prefix to be set using the :auto_id_prefix API option or --auto-id-prefix CLI option. This value would only be used if auto-generated IDs are enabled. (We could also consider allowing the prefix to be set using the value of the :auto_ids / --auto-ids option).

Preserving frontmatter for hugo

Hello,

Thank you for creating kramdown.

I am converting md files in Hugo.

How can I use kramdown to convert and still preserve the frontmatter? Hugo will not render with frontmatter.

Move mkpath from the convert_file method to the convert method

Now that the convert API method accepts a target file (as a string or Pathname object), it should handle creating any intermediary directories instead of convert_file. All the convert_file method should be doing before delegating to convert is to read the input file and potentially set the output file if left unspecified.

Add option to convert_file API to return output as a string

The convert_file API assumes that if you read the input from a file, you also want to write the output to a file or IO object. However, this is not always the case. Sometimes, you want to return the document to perform further processing on it. The :to option should accept a value that indicates the output string should returned instead of written to a file or IO object.

The values being considered are as follows:

  • false
  • :string
  • nil (this value may be too ambiguous)

Error on lists with items with only spaces

I've installed the gem kramdown-asciidocbut if fails:

 ~/bin/kramdoc --output=Apuntes.adoc Apuntes.md 
Traceback (most recent call last):
        21: from /home/sergio/bin/kramdoc:23:in `<main>'
        20: from /home/sergio/bin/kramdoc:23:in `load'
        19: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/bin/kramdoc:12:in `<top (required)>'
        18: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/cli.rb:117:in `run'
        17: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/api.rb:104:in `convert_file'
        16: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/api.rb:52:in `convert'
        15: from /home/sergio/.gem/ruby/gems/kramdown-1.17.0/lib/kramdown/document.rb:117:in `method_missing'
        14: from /home/sergio/.gem/ruby/gems/kramdown-1.17.0/lib/kramdown/converter/base.rb:105:in `convert'
        13: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:99:in `convert'
        12: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:105:in `convert_root'
        11: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `traverse'
        10: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each_with_index'
         9: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each'
         8: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:646:in `block in traverse'
         7: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:99:in `convert'
         6: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:299:in `convert_ul'
         5: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `traverse'
         4: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each_with_index'
         3: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each'
         2: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:646:in `block in traverse'
         1: from /home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:99:in `convert'
/home/sergio/.gem/ruby/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:312:in `convert_li': undefined method `type' for nil:NilClass (NoMethodError)

Versions:

  • gem environment version
    3.1.4

  • ruby
    ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]

The problem as far I tested is due to items containing only spaces on a item of a list, for example the convertion will fail:

# Ejemplo

- item 1
- item 2
- item 3
- item 4
- item 5
- item 6
- item 7
- 
- item 8

Simply deleting empty items prevents this issue.

It would be nice that kramdoc print a nicer error message in such a cases.

Thanks in advance!

Escape unintended replacements in codespan

If there are characters in the Markdown source that have special meaning in AsciiDoc, escape these if they appear inside a codespan. One idea is to simply use a passthrough for anything other than vanilla text.

Example:

`foo--bar`

which should become:

`+foo--bar+`

Add support for multi-paragraph admonitions

I really appreciate the way that kramdown-asciidoc turns regular Markdown paragraphs into proper AsciiDoc admonitions, if they begin with a typical admonition marker such as Note:. In addition to this, I'd like a way of marking up a multi-paragraph admonition in Markdown, so that kramdown-asciidoc will convert it into a single AsciiDoc admonition block.

Possible markup: !!! as used in python-markdown, mkdocs. This seems to have support on multiple platforms, but it doesn't degrade gracefully when using markdown processors that don't support this markup.

Another possible markup: ::: fenced_divs ::: as used in pandoc with the fenced_divs extension. Doesn't seem to be so widely recognized. Also doesn't degrade gracefully.

My preferred solution would be to recognize a blockquote > starting with any of the current admonition markers as an admonition. This degrades gracefully. It also has the advantage that it is compatible with the markdown output from pandoc -- useful for toolchain pipelines.

undefined method convert_xml_pi

While attempting to convert a Markdown file to Asciidoc with kramdoc, I encountered the following error. I thought it worth reporting, just in case it was unknown. I can provide a copy of the source file, if required.

Traceback (most recent call last):
	14: from /usr/local/bin/kramdoc:23:in `<main>'
	13: from /usr/local/bin/kramdoc:23:in `load'
	12: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/bin/kramdoc:12:in `<top (required)>'
	11: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/cli.rb:117:in `run'
	10: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/api.rb:104:in `convert_file'
	 9: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/api.rb:52:in `convert'
	 8: from /Library/Ruby/Gems/2.6.0/gems/kramdown-1.17.0/lib/kramdown/document.rb:117:in `method_missing'
	 7: from /Library/Ruby/Gems/2.6.0/gems/kramdown-1.17.0/lib/kramdown/converter/base.rb:105:in `convert'
	 6: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:99:in `convert'
	 5: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:105:in `convert_root'
	 4: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `traverse'
	 3: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each_with_index'
	 2: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each'
	 1: from /Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:646:in `block in traverse'
/Library/Ruby/Gems/2.6.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:99:in `convert': undefined method `convert_xml_pi' for #<Kramdown::AsciiDoc::Converter:0x00007fdcb00ac668> (NoMethodError)
Did you mean?  convert_li

Configure kramdown to strip markup from raw text for generating IDs when input is not GFM

When the input is GFM, kramdown automatically strips markup from the raw text of the heading for the purpose of generating an ID. However, it does not do this by default when the input is not GFM (markdown or kramdown). Sync this option across input formats so that IDs are generated consistently.

We may even want to look into using our own stripping logic that preserves character references in their original form. That will ensure better alignment between IDs generated by kramdoc and the AsciiDoc processor.

Literal paragraph that starts with list marker gets interpreted as a list

When converting an indented Markdown codeblock to an AsciiDoc literal paragraph, check whether the content begins with a list marker (list or dlist). For example:

* Connected to localhost (127.0.0.1) port 5252 (#0)
> GET / HTTP/1.1
> Host: localhost:5252

Markdown and AsciiDoc don't interpret the content the same way in this case. AsciiDoc treats the content as a list. Accommodations must be made to prevent this outcome.

Two possible solutions are:

  1. Enclose the content in a literal block
  2. Add the line [literal,indent=0] above the block

Add Dockerfile

Add your bundle/binary to a Dockerfile and release it to Dockerhub. I'd love to integrate and use it in my CI pipelines.

Is it planned? If not I'd contribute

convert_file should honor the value of the :to option

The convert_file API should allow an alternate output file to be specified using the :to option. Currently, this option is only available to the convert API. The convert_file API always writes the output to a file adjacent to the input file.

Kramdoc.convert_file 'sample.md', to: 'alternate/path/to/sample.adoc'

Sort document header attributes

Document header attributes can be contributed from a variety of sources. Sort them before writing them to the document to maintain consistency.

Add postprocess callback to convert_file API

Add an optional postprocess callback to the convert_file API so the converted result can be manipulated before being written to the output file. The callback should accept the generated AsciiDoc string as the first argument (and possibly the options as the second).

Example:

Kramdoc.convert_file markdown_file, postprocess: -> (str) { str.gsub '{pp}', '++' }

Without this callback, it's necessary to fallback to the convert method, which means having to handle reading the input file manually.

undefined method `start_with?' for nil:NilClass

Hello maintainers, thanks for your hard work!

On certain files i get the following error:

Traceback (most recent call last):
        15: from /usr/local/bundle/bin/kramdoc:23:in `<main>'
        14: from /usr/local/bundle/bin/kramdoc:23:in `load'
        13: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/bin/kramdoc:13:in `<top (required)>'
        12: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/cli.rb:120:in `run'
        11: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/api.rb:107:in `convert_file'
        10: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/api.rb:55:in `convert'
         9: from /usr/local/bundle/gems/kramdown-2.3.1/lib/kramdown/document.rb:116:in `method_missing'
         8: from /usr/local/bundle/gems/kramdown-2.3.1/lib/kramdown/converter/base.rb:107:in `convert'
         7: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:102:in `convert'
         6: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:108:in `convert_root'
         5: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:667:in `traverse'
         4: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:667:in `each_with_index'
         3: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:667:in `each'
         2: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:668:in `block in traverse'
         1: from /usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:102:in `convert'
/usr/local/bundle/gems/kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb:235:in `convert_codeblock': undefined method `start_with?' for nil:NilClass
 (NoMethodError)

I have no experience in ruby, thus i'm not trying to submit a pull request, but i fixed it locally by patching kramdown-asciidoc-2.0.0/lib/kramdown-asciidoc/converter.rb, line 235:

elsif (lines.length > 0) && (prompt = lines[0].start_with? '$ ')

Wrap list continuation inside a block

I found a case that seems like a bug in Asciidoc's handling of continuation of lists, however it could be avoided if the continuation of list is created within a block.

https://docs.asciidoctor.org/asciidoc/latest/lists/continuation/#list-continuation

Markdown Source

# Title 

1.  Example


    -  ListItem1
    -  ListItem2

    ```
    tar -xvf 1.0-Linux32.tar.gz
    ```
    
    
    Paragraph


    ```
    ls
    ```

Asciidoc Output

= Title

. Example
 ** ListItem1
 ** ListItem2

+
----
tar -xvf 1.0-Linux32.tar.gz
----
+
Paragraph
+
----
ls
----

HTML Result using adoc file
screenshot-www google com-2021 07 29-09_57_13

Constrained/unconstrained quotes

Quotes should be doubled when there is no space before/after the text.

In my case the documents are in Japanese, so there is no space between words. An example:

Markdown text: 計算の過程で`NaN`や`Inifinite`が出た際に
Kramdoc output: 計算の過程で`NaN`や`Inifinite`が出た際に
Expected output: 計算の過程で``NaN``や``Inifinite``が出た際に

`convert': undefined method `convert_footnote'

I'm getting an error when trying to use kramdoc on this https://raw.githubusercontent.com/rust-lang/book/master/src/ch08-03-hash-maps.md:

C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:99:in `convert': undefined method `convert_footnote' for #<Kramdown::AsciiDoc::Converter:0x000000000588c200> (NoMethodError)
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:646:in `block in traverse'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each_with_index'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `traverse'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:658:in `compose_text'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:193:in `convert_p'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:99:in `convert'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:646:in `block in traverse'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `each_with_index'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:645:in `traverse'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:105:in `convert_root'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/converter.rb:99:in `convert'
	from C:/ruby/gems/gems/kramdown-1.17.0/lib/kramdown/converter/base.rb:105:in `convert'
	from C:/ruby/gems/gems/kramdown-1.17.0/lib/kramdown/document.rb:117:in `method_missing'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/api.rb:52:in `convert'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/api.rb:104:in `convert_file'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/cli.rb:117:in `run'
	from C:/ruby/gems/gems/kramdown-asciidoc-1.0.1/bin/kramdoc:12:in `<top (required)>'
	from C:/apps/ruby/current/gems/bin/kramdoc:23:in `load'
	from C:/apps/ruby/current/gems/bin/kramdoc:23:in `<main>'

Add lazy ID option

Add an option to skip ID generation if the value matches the auto-generated value. This could either be expressed as the option :lazy_ids or it could be a special value of the :auto_ids option.

Add a converter API

Add a top-level converter API that encapsulates instantiating the Kramdown document and invoking the to_asciidoc method on it. To match the CLI name, the API should be named Kramdoc.

  • Kramdoc.convert_file file
  • Kramdoc.convert string

Update the CLI to use this API instead of interfacing with Kramdown directly.

Write files as UTF-8

Just to be safe and not rely on platform defaults, we should explicitly write files using UTF-8 encoding. This is just a matter of specifying the encoding when calling IO.write command. We already know that the string we are writing is UTF-8.

Add docs to methods in public API

To help developers use the kramdown-asciidoc API, add docs to the methods that comprise the public API. In particular, document Kramdoc.convert and Kramdoc.convert_file.

Add role to codespan if wrapped in quotes

If a codespan (aka monospaced text) is wrapped in quotes, it's not enough to use unconstrained formatting marks. The formatting marks must also have a role.

Incorrect:

"``foo bar``"

Correct:

"[.code]``foo bar``"

(The role doesn't matter, though .code certainly expresses the intent).

Unable to converto to Asciidoc, `method_missing': undefined method `to_e.adoc'·

Hi,

I'm running ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu],
and installed kramdown from the public gems repo which is, at this moment, kramdown-asciidoc-1.0.1

I tried to use it convert a markdown file to asciidoc and got the following exception,

(base) gabriel@yvon:~$ kramdown -o e.adoc export-tree.md 
/var/lib/gems/2.3.0/gems/kramdown-1.17.0/lib/kramdown/document.rb:121:in `method_missing': undefined method `to_e.adoc' for #<Kramdown::Document:0x005588f7a8ee88> (NoMethodError)
        from /var/lib/gems/2.3.0/gems/kramdown-1.17.0/bin/kramdown:98:in `block in <top (required)>'
        from /var/lib/gems/2.3.0/gems/kramdown-1.17.0/bin/kramdown:98:in `each'
        from /var/lib/gems/2.3.0/gems/kramdown-1.17.0/bin/kramdown:98:in `<top (required)>'
        from /usr/local/bin/kramdown:22:in `load'
        from /usr/local/bin/kramdown:22:in `<main>'

question about attributes

Hello,

I want to use custom attributes in generated asciidoctor file.
So in md (not GFM) I define a Yaml Front Matter with my "custom-attribute" and in the body of the document I try to use it with the syntax {custom-attribute}.
but during kramdown-asciidoc conversion, {custom-attribute} becomes {custom-attribute}, why ? and how can I change this ?

thx

Add support for multiple postprocessors

Currently, it's possible to supply multiple preprocessors, but not multiple postprocessors. Add support for passing multiple postprocessors using the :postprocessors option. If specified, the :postprocessors option takes precedence over the :postprocess option (the two are mutually exclusive).

Add a proper CLI with options and help

Currently, the CLI just runs a pre-configured operation and is not at all interactive. Add a CLI that shows the standard CLI banner and colophon (help, version, etc) and which can be used to configure the converter.

The following set of options should be supported initially:

  • output (-o) (the output filename or stream)
  • attribute (-a) (can be specified multiple times)
  • wrap=none|preserve|ventilate (and perhaps in the future auto, wrapping at a fixed length)
  • flavor=kramdown|gfm|default
  • smart (-S)
  • lazy-ids
  • heading-offset
  • html=preserve|native

The primary focus of this issue is getting the foundation in place for the CLI. If one or more of these options has to be dropped for the first draft, that's fine.

Ventilate prose at additional punctuation breaks

In addition to a full stop (i.e., period), also break lines on an explanation point and question mark.

Also consider whether to split on a semi-colon. Perhaps the later should be an option.

Use writer to track heading level

Given that the writer is a structured writer, it makes sense for it to track the heading level like it does the list depth. Add the APIs necessary to use the writer for this purpose.

Define id using attribute if value contains a period

If an id contains a period (.), it must be written out longhand using the id attribute instead of shorthand. The reason this must be done is because the period has special meaning in the shorthand syntax.

Example:

[id=a.b.c]
== Section Title

Quotes aren't necessary since the ID should not contain quotes, spaces, or commas.

Detect diagram type

I use kramdoc as a converter to be able to transform markdown to pdf (Asciidoc is awesome, but our documentation generator only support markdown).

My current script looks like this:

#!/usr/bin/env sh
#This scripts require the installation of the ruby gems asciidoctor, asciidoctor-pdf, kramdoc and rouge

kramdoc "$1" -o - | asciidoctor-pdf -a "source-highlighter=rouge" -r rouge -o "${1%.*}.pdf" -

I would love to be able to also generate diagrams during the process, using asciidoctor-diagram.

Howerver, if i write in my markdown file :

```plantuml
@startuml
Alice --> Bob: Hello
@enduml
```

It will be converted to

[source, plantuml]
----
@startuml
Alice --> Bob: Hello
@enduml
----

when this output would be more useful.

[plantuml]
----
@startuml
Alice --> Bob: Hello
@enduml
----

render source highlighting above a code block correctly

When I run:

find ./ -name "*.md"  \
    -type f \
    -exec sh -c  \
    'kramdoc --format=GFM  \
    --output={}.adoc {}' \;

against /docs in a local clone of https://github.com/rolfedh/build, kramdown renders code blocks as h2's.

For example, line 71+ of docs/build.md input file looks like this:

[source,yaml]
----
apiVersion: build.dev/v1alpha1
kind: Build
metadata:
  name: buildpack-nodejs-build
spec:
  source:
    url: https://github.com/sclorg/nodejs-ex
    credentials:
      name: source-repository-credentials
----

And line 71+ of the build.md.adoc output file looks like this:

== [source,yaml]

apiVersion: build.dev/v1alpha1
kind: Build
metadata:
  name: buildpack-nodejs-build
spec:
  source:
    url: https://github.com/sclorg/nodejs-ex
    credentials:
      name: source-repository-credentials
----

Markdown with blockquotes can not be converted

kramdown-asciidoc/converter.rb:21:in `block in inner': undefined method `convert_blockquote' for #<Kramdown::Converter::Asciidoc:0x00000002b574b0> (NoMethodError)
Did you mean?  convert_root
    from /home/martin/develop/git/kramdown-asciidoc/lib/kramdown-asciidoc/converter.rb:17:in `each'
    from /home/martin/develop/git/kramdown-asciidoc/lib/kramdown-asciidoc/converter.rb:17:in `each_with_index'
    from /home/martin/develop/git/kramdown-asciidoc/lib/kramdown-asciidoc/converter.rb:17:in `inner'
    from /home/martin/develop/git/kramdown-asciidoc/lib/kramdown-asciidoc/converter.rb:29:in `convert_root'
    from /home/martin/develop/git/kramdown-asciidoc/lib/kramdown-asciidoc/converter.rb:10:in `convert'
    from /usr/lib/ruby/gems/2.3.0/gems/kramdown-1.7.0/lib/kramdown/converter/base.rb:105:in `convert'
    from /usr/lib/ruby/gems/2.3.0/gems/kramdown-1.7.0/lib/kramdown/document.rb:120:in `method_missing'
    from /home/martin/develop/git/kramdown-asciidoc/bin/kramdown-asciidoc:24:in `<main>'

markdown containing quotes with leading ">" cannot be converted (blocks propably should be convertet to be wrapped with "___" or have leading "[quote]")

there is no convert_blockquote method
(I tried to add it, but without ever having written a line of ruby, I couldn't make it work :) )

other then that it works great so far (better then pandoc, don't like underlined titles)
Thank You!

Add option to drop unconverted HTML

To handle cases when raw HTML gets left behind, add an option to either drop it or convert it to plain text. Currently, raw HTML is escaped using a triple-plus passthrough.

Drop bare <span> element

If element is bare, just drop it (leaving behind only the contents). If the element contains one or more CSS classes, pass them on using roles on an unquoted phrase.

kramdoc:3: syntax error

I'm using macOS 10.13.6. Calling kramdoc gives the following error:

$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]
$ sudo gem install kramdown-asciidoc
Fetching: kramdown-1.17.0.gem (100%)
Successfully installed kramdown-1.17.0
Fetching: kramdown-asciidoc-1.0.0.gem (100%)
Successfully installed kramdown-asciidoc-1.0.0
Parsing documentation for kramdown-1.17.0
Installing ri documentation for kramdown-1.17.0
Parsing documentation for kramdown-asciidoc-1.0.0
Installing ri documentation for kramdown-asciidoc-1.0.0
Done installing documentation for kramdown, kramdown-asciidoc after 2 seconds
2 gems installed
$ kramdoc -h
/usr/local/bin/kramdoc:22:in `load': /Library/Ruby/Gems/2.3.0/gems/kramdown-asciidoc-1.0.0/bin/kramdoc:3: syntax error, unexpected tSTRING_BEG, expecting ')' (SyntaxError)
...asciidoc = File.absolute_path '../lib/kramdown-asciidoc', __...
...                               ^
/Library/Ruby/Gems/2.3.0/gems/kramdown-asciidoc-1.0.0/bin/kramdoc:3: syntax error, unexpected ',', expecting end-of-input
...ath '../lib/kramdown-asciidoc', __dir__)
...                               ^
	from /usr/local/bin/kramdoc:22:in `<main>'

Doesn't work out of the box on Ruby 3

When trying kramdoc after gem install kramdown-asciidoc, I've got the following error:

<internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- rexml/parsers/baseparser (LoadError)
	from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /home/vt/.local/share/gem/ruby/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/html.rb:10:in `<top (required)>'
	from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /home/vt/.local/share/gem/ruby/3.0.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc/kramdown_ext/parser/html.rb:1:in `<top (required)>'
	from /home/vt/.local/share/gem/ruby/3.0.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc.rb:3:in `require_relative'
	from /home/vt/.local/share/gem/ruby/3.0.0/gems/kramdown-asciidoc-1.0.1/lib/kramdown-asciidoc.rb:3:in `<top (required)>'
	from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /home/vt/.local/share/gem/ruby/3.0.0/gems/kramdown-asciidoc-1.0.1/bin/kramdoc:5:in `<top (required)>'
	from /home/vt/.local/share/gem/ruby/3.0.0/bin/kramdoc:23:in `load'
	from /home/vt/.local/share/gem/ruby/3.0.0/bin/kramdoc:23:in `<main>'

The tests fail on Kramdown::Parser::Html::ElementConverter.

  • ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]
  • gem 3.2.15
  • Bundler version 2.2.16

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.