asciidoctor / asciidoctor.js

:scroll: A JavaScript port of Asciidoctor, a modern implementation of AsciiDoc
https://asciidoctor.org
MIT License
739 stars 136 forks source link

Add support for asciidoc source metadata #467

Closed joaompinto closed 6 years ago

joaompinto commented 6 years ago

In order to address https://github.com/joaompinto/asciidoctor-vscode/issues/11, which relies on Asciidocttor(.js) the Asciidoctor html output would need to include source line meta data.

As an example, te VS Code markdown extension which provides this feature, relies on extra meta data added to the html elements: e.g.. class="code-line" data-line="10>.. html content .

ggrossetie commented 6 years ago

Hello @joaompinto, I think what you are looking for is the sourcemap option: https://asciidoctor.org/docs/user-manual/#ruby-api-options

You can look at the Atom source code where @ldez implemented a "scroll to source" feature.

  1. Define the sourcemap option: https://github.com/asciidoctor/atom-asciidoc-preview/blob/11a702bb804497a5c02544b9e6e71e0384f80322/lib/worker.coffee#L30
  2. Register blocks position (using lineno): https://github.com/asciidoctor/atom-asciidoc-preview/blob/11a702bb804497a5c02544b9e6e71e0384f80322/lib/worker.coffee#L55-L77
joaompinto commented 6 years ago

@Mogztter , thanks for the help.

I have looked at the AsciidoctorJS source to figure how to use loadFile(), findBy(), getLineNumber(). addRole() .

https://github.com/joaompinto/asciidoctor-vscode/commit/9f04dad0852532f0b52ce42346f58076d3af61dc

I am closing the issue, when I have some more time I will open a new issue for the documentation, https://github.com/asciidoctor/asciidoctor.js/blob/master/docs/manual.adoc did not provide any hint to the available options and how to explore the document content (besides converting).