benrbray / remark-cite

Adds support for pandoc-style citations to the Markdown syntax for the remark and micromark parsers.
MIT License
20 stars 5 forks source link

Citations converted to text node not citeItems #1

Closed benjamineskola closed 1 month ago

benjamineskola commented 2 years ago

I'm trying to use Remark (via remark-cli) to ensure uniform formatting in my Markdown documents; as I use Pandoc I'd like to use remark-cite to preserve the citations (as otherwise, the opening square bracket is escaped with a backslash). However, including the plugin doesn't appear to affect the output that is generated.

Using the example from the documentation:

test.md:

[see @wadler1989, sec. 1.3; and -@hughes1990, pp.4]

Minimal config in ~/.remarkrc.yml (other plugins/settings removed to confirm they're not interfering):

plugins:
  - "@benrbray/remark-cite"
$ remark --tree-out ~/test.md
{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "[see @wadler1989, sec. 1.3; and -@hughes1990, pp.4]",
          "position": {
            "start": {
              "line": 1,
              "column": 1,
              "offset": 0
            },
            "end": {
              "line": 1,
              "column": 52,
              "offset": 51
            }
          }
        }
      ],
      "position": {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "end": {
          "line": 1,
          "column": 52,
          "offset": 51
        }
      }
    }
  ],
  "position": {
    "start": {
      "line": 1,
      "column": 1,
      "offset": 0
    },
    "end": {
      "line": 2,
      "column": 1,
      "offset": 52
    }
  }
}

I feel like this might be a misconfiguration on my part, as I found the documentation for config files and how plugin settings map onto them to be a little unclear, and I had issues with that with other settings. But in this case enablePandocSyntax should be true by default, and it doesn't even seem to be parsing in the first place — but I presume the module is being loaded, because specifying a nonexistent plugin name causes an error. Any suggestions for how to debug this would be appreciated.

benrbray commented 2 years ago

Congratulations on filing issue #1 :)

I haven't used remark-cli before, but I was able to reproduce the problem on my machine.

It looks like remark-cli is a thin wrapper around unified-args which just passes config to unified-engine. I spent some time trying to determine how exactly the plugins config for remark-cli actually influences the markdown processor, but the code is a bit hard to follow.

It's not clear to me what "plugin" means in the context of remark-cli. I found this page, which seems to suggest that some extra code needs to be written to support unified-engine. It's not clear to me if plugins can alter the markdown syntax. Have you had success with other syntax extensions?

I started a discussion in the remark repo so hopefully we can get some guidance from the maintainer. PR's are welcome to this repo by the way ;)

benjamineskola commented 2 years ago

I've used a few other extensions successfully. remark-frontmatter is a good example. When it's disabled, yaml front matter is treated as just some markdown and reformatted; when it's enabled, it's preserved as yaml. Similarly, remark-wiki-link — when disabled, a sequence [[foo]] gets escaped as \[\[foo]], and when enabled it's preserved.

However I don't really see what those do differently to your plugin.

edit: actually, one difference seems to be that they both export a default function: here and here but I can't tell if that's significant. remark-gfm and remark-footnotes do likewise.

benrbray commented 1 month ago

I'm closing this since I believe it should be fixed by recent changes (including a default export). Please feel free to reopen if the issue is still affecting you!