azu / gitbook-plugin-include-codeblock

GitBook plugin for including file
Other
40 stars 25 forks source link

Breaks ordered list numbering #45

Open pauleveritt opened 7 years ago

pauleveritt commented 7 years ago

I'm trying to do an include in the middle of a sequence of steps:

1. Some step

    ![Some Screenshot](path/to/image.png)

2. Next step

    [include](../path/to/file.js)

3. Last step

The image gets included without breaking the numbering. But the include makes "Last step" closes the preceding list with </ol>, then inserts a <pre>, then starts a new <ol>.

azu commented 7 years ago

I've confirmed that is a bug.

1. Some step

    ```js
    var a = 1;
    ```

2. Next step

    [import, hello-world.js](../src/hello-world.js)

3. Last step

to be

hello world gitbook 2017-02-16 18-12-31

jany-tenaj commented 7 years ago

Is there any hope that this will get fixed soon?

lwchkg commented 6 years ago

Trying to propose an analysis and propose a solution. Azu: please see if the solution looks good. If it sounds good I'll write a patch.

Analysis:

  1. Markdown uses indents for fenced code blocks.
  2. AsciiDoctor does not allow indents for fenced code blocks. If indents are added the fenced code block breaks.
  3. the template code for code is
    ```{{lang}}
    {{{content}}}
    ```

    So we need to indent both {{{code}}} and ```

Proposed solution:

  1. Change the template to the following:

    {{indent}}```{{lang}}
    {{{indented_content}}}
    {{indent}}```
  2. Users should put spaces, i.e. [ \t]*, before the [include...]() tag to add indents. For markdown pages, {{indent}} becomes the exact spaces added before the [include] tag. For AsciiDoctor pages, {{indent}} is always nothing so users don't add indents by mistake.

  3. {{{indented_code}}} is the code indented with {{indent}} at the beginning of each line.