kdheepak / panvimdoc

Write documentation in pandoc markdown. Generate documentation in vimdoc.
https://kdheepak.com/panvimdoc
MIT License
263 stars 15 forks source link

Ignore comments not working #10

Closed akinsho closed 2 years ago

akinsho commented 2 years ago

Hi @kdheepak,

Thanks for your work on this project, it's super helpful 🙏🏿. I just added it to my https://github.com/akinsho/toggleterm.nvim plugin, but I'm seeing that when I use the ignore comments to try to omit the HTML at the start of the README the rest of the help doc is not converted correctly ie.

<!-- panvimdoc-ignore-start -->
<h1 align="center">
  toggleterm.nvim
</h1>

<p align="center">A <i>neovim</i> plugin to persist and toggle multiple terminals during an editing session</p>

![screenshot](./github/toggleterm.gif "Toggleterm in action")

### Multiple orientations

- **Float**

![floating window](https://user-images.githubusercontent.com/22454918/115306123-42d2ac00-a15f-11eb-84fc-c4246ee82a09.png)

- **Vertical**

![vertical orientation](./github/vertical-terms.png)

- **Tab**

![tab orientation](https://user-images.githubusercontent.com/22454918/133490969-6a59e623-79db-4ca7-a73b-ef4b24a73b91.gif)

### Send commands to different terminals

![exec](https://user-images.githubusercontent.com/22454918/112119367-36d1e980-8bb5-11eb-9787-5936391127a3.gif)

<!-- panvimdoc-ignore-end -->

When adjusting the README to the above, this does not work as intended and the rest of the README is omitted during the conversion

kdheepak commented 2 years ago

Try it like this:

<!-- panvimdoc-ignore-start -->
<h1 align="center">
  toggleterm.nvim
</h1>

<p align="center">A <i>neovim</i> plug

<!-- panvimdoc-ignore-end -->

![screenshot](./github/toggleterm.gif "Toggleterm in action")

### Multiple orientations

…
kdheepak commented 2 years ago

Whatever is in between the start and end comment “tag” is ignored. Does that make sense?

akinsho commented 2 years ago

Will give that a shot. So do I essentially have to wrap each html tag individually? I wonder why the the tags placed as they are in my example don't work i.e. both start and end are present it just doesn't seem to catch the end tag in my example

kdheepak commented 2 years ago

So do I essentially have to wrap each html tag individually?

If you want the html tag to appear in the markdown, and do not want them to appear in the vimdoc, you'll have to do that.

kdheepak commented 2 years ago

it just doesn't seem to catch the end tag in my example

What do you mean it doesn't catch the end tag?

kdheepak commented 2 years ago

This script is what replaces everything between start and end tags with empty pandoc objects: https://github.com/kdheepak/panvimdoc/blob/main/scripts/skip-blocks.lua

kdheepak commented 2 years ago

@akinsho is this working for you? If yes, I'll close this issue.

akinsho commented 2 years ago

Sorry @kdheepak for leaving this open for this long, I've actually been completely sideswided by work and life and haven't had the opportunity to try it yet. I'll give it a go this evening and report back. If you don't hear back from me, just close the issue and I'll comment on here something if comes up

kdheepak commented 2 years ago

No worries, I’ve been swamped with work too. I can leave it open until you get back. I just tested it too, so I’m pretty sure it works as a GitHub action with the pandoc version in the docker image. So I’m curious what’s going on on your end.

akinsho commented 2 years ago

@kdheepak I just tried again wrapping each tag I wanted to exclude manually and it essentially removes all the contents from my help file.

<!-- panvimdoc-ignore-start -->
<h1 align="center">
  toggleterm.nvim
</h1>
<!-- panvimdoc-ignore-end -->

<!-- panvimdoc-ignore-start -->
<p align="center">A <i>neovim</i> plugin to persist and toggle multiple terminals during an editing session</p>
<!-- panvimdoc-ignore-end -->

<!-- panvimdoc-ignore-start -->
![screenshot](./github/toggleterm.gif "Toggleterm in action")
<!-- panvimdoc-ignore-end -->

### Multiple orientations

- **Float**

<!-- panvimdoc-ignore-start -->
![floating window](https://user-images.githubusercontent.com/22454918/115306123-42d2ac00-a15f-11eb-84fc-c4246ee82a09.png)
<!-- panvimdoc-ignore-end -->

- **Vertical**

<!-- panvimdoc-ignore-start -->
![vertical orientation](./github/vertical-terms.png)
<!-- panvimdoc-ignore-end -->

- **Tab**

<!-- panvimdoc-ignore-start -->
![tab orientation](https://user-images.githubusercontent.com/22454918/133490969-6a59e623-79db-4ca7-a73b-ef4b24a73b91.gif)
<!-- panvimdoc-ignore-end -->

### Send commands to different terminals

<!-- panvimdoc-ignore-start -->
![exec](https://user-images.githubusercontent.com/22454918/112119367-36d1e980-8bb5-11eb-9787-5936391127a3.gif)
<!-- panvimdoc-ignore-end -->

This results in

*toggleterm.txt*plugin to persist and toggle multiple terminals during an editing session

==============================================================================
Table of Contents                               *toggleterm-table-of-contents*

Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>

vim:tw=78:ts=8:noet:ft=help:norl:
kdheepak commented 2 years ago

I'm able to replicate this! I'll look into this now.

kdheepak commented 2 years ago

I know what is going on but I don't know how to solve it. Basically, pandoc runs the filter for all RawInline elements before it runs the filter for RawBlock elements. And this means that if you have:

<!-- panvimdoc-ignore-start -->
![screenshot](./github/toggleterm.gif "Toggleterm in action")
<!-- panvimdoc-ignore-end -->

It gets parsed as

{
  "pandoc-api-version": [
    1,
    22,
    1
  ],
  "meta": {
    "project": {
      "t": "MetaString",
      "c": "panvimdoc"
    }
  },
  "blocks": [
    {
      "t": "RawBlock",
      "c": [
        "html",
        "<!-- panvimdoc-ignore-start -->"
      ]
    },
    {
      "t": "Para",
      "c": [
        {
          "t": "Image",
          "c": [
            [
              "",
              [],
              []
            ],
            [
              {
                "t": "Str",
                "c": "screenshot"
              }
            ],
            [
              "./github/toggleterm.gif",
              "Toggleterm in action"
            ]
          ]
        },
        {
          "t": "SoftBreak"
        },
        {
          "t": "RawInline",
          "c": [
            "html",
            "<!-- panvimdoc-ignore-end -->"
          ]
        }
      ]
    }
  ]
}

And because it parses the "start" and "end" as different types, the checks for all the "end" tags happen before the "start" tag. And the "start" tag is the one that sets a variable that tracks whether the filter should ignore the content, and because the "end"s have already been processed, it is never unset.

The easiest solution to this is to add new lines before and after all "comment" tags, e.g.:

<!-- panvimdoc-ignore-start -->

<h1 align="center">
  toggleterm.nvim
</h1>

<!-- panvimdoc-ignore-end -->

<!-- panvimdoc-ignore-start -->

<p align="center">A <i>neovim</i> plugin to persist and toggle multiple terminals during an editing session</p>

<!-- panvimdoc-ignore-end -->

<!-- panvimdoc-ignore-start -->

![screenshot](./github/toggleterm.gif "Toggleterm in action")

<!-- panvimdoc-ignore-end -->

### Multiple orientations

- **Float**

<!-- panvimdoc-ignore-start -->

![floating window](https://user-images.githubusercontent.com/22454918/115306123-42d2ac00-a15f-11eb-84fc-c4246ee82a09.png)

<!-- panvimdoc-ignore-end -->

- **Vertical**

<!-- panvimdoc-ignore-start -->

![vertical orientation](./github/vertical-terms.png)

<!-- panvimdoc-ignore-end -->

- **Tab**

<!-- panvimdoc-ignore-start -->

![tab orientation](https://user-images.githubusercontent.com/22454918/133490969-6a59e623-79db-4ca7-a73b-ef4b24a73b91.gif)

<!-- panvimdoc-ignore-end -->

### Send commands to different terminals

<!-- panvimdoc-ignore-start -->

![exec](https://user-images.githubusercontent.com/22454918/112119367-36d1e980-8bb5-11eb-9787-5936391127a3.gif)

<!-- panvimdoc-ignore-end -->

This gets rendered as the following:

*panvimdoc.txt*          For NVIM v0.7.0          Last change: 2022 January 26

==============================================================================
Table of Contents                                *panvimdoc-table-of-contents*

MULTIPLE ORIENTATIONS ~

- **Float**

- **Vertical**

- **Tab**

SEND COMMANDS TO DIFFERENT TERMINALS ~

Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>

vim:tw=78:ts=8:noet:ft=help:norl:
kdheepak commented 2 years ago

I added a section to the specification documentation: https://github.com/kdheepak/panvimdoc/blob/c50c5d5b898dbf1f850f0144f5b7f863bb4f1d8c/doc/panvimdoc.md?plain=1#L319-L335.

Short of using a different markdown parser, this appears to be the only way to resolve this issue.

akinsho commented 2 years ago

Awesome, that works, thanks 👍🏿