asciidoctor / asciidoctor-vscode

AsciiDoc support for Visual Studio Code using Asciidoctor
Other
324 stars 97 forks source link

Can not swith to other source code syntax highlighter to show line number #803

Closed Jasper-Li closed 5 months ago

Jasper-Li commented 9 months ago

I want to show line number in source code. As asciidoctor official doc says:

When using Asciidoctor, the only syntax highlighter that does not support line numbering is highlight.js.

Which is from: https://docs.asciidoctor.org/asciidoc/latest/verbatim/source-highlighter/#enable-line-numbering

I must switch to another syntax hightlighter like rouge, coderay.

Before I used an asciidoctor CLI in my local machine.

After "Asciidoctor CLI Dropped" from asciidoctor-vscode version 3.0, I failed to show line nubmer for a source block.

In a summary,

  1. How to show line number in source bloock?
  2. Methods to switch syntax highlighter

Thanks

ggrossetie commented 9 months ago

The VS Code Extension is written in JavaScript and uses Asciidoctor.js. Highlight.js is the only built-in syntax highlighter supported by Asciidoctor.js.

If you want to use another syntax highlighter, you will need to use the asciidoctor CLI. As mentioned in the release notes, you can use both the HTML Preview and Run on Save extensions with the following settings.json:

{
    "emeraldwalk.runonsave": {
        "commands": [
            {
                "match": "\\.adoc$",
                "cmd": "asciidoctor ${file}"
            },
        ]
    }
}

You can also setup a workflow outside of VS Code that relies on the asciidoctor CLI.

Another solution would be to integrate Prism as a syntax highlighter with the line number plugin: https://prismjs.com/plugins/line-numbers

Yet another solution would be to include https://github.com/wcoder/highlightjs-line-numbers.js using docinfo files (I don't recall if the VS Code Extension supports docinfo).

Jasper-Li commented 9 months ago

Thanks very much. I think the HTML Preview and Run on Save method is not smooth on using.

Prism or highlightjs-line-numbers.js is a better solution. Does developer team have a plan on source block line number showing? It's a common need on technical writing.

ggrossetie commented 5 months ago

Not sure but you could contribute to https://github.com/thom4parisot/asciidoctor-prism-extension/issues/2 if you want a syntax highlighter with line numbers