Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape square brackets, braces and at characters in text nodes (fixes #4) #9

Merged
merged 1 commit into from
Oct 2, 2022

Conversation

dmbaturin
Copy link
Contributor

As @Niols pointes out in #4,

special characters (’{’, ’}’, ’[’, ’]’ and ’@’) must be escaped by a ’\’.

None of these characters have any special meaning by themselves in Markdown. Square brackets only have a special meaning in the [<link text>](<link address>) syntax, and in that case Omd returns an Omd.Link node so they don't appear in the text. The only case when they can appear and need escaping is Omd.Text.

One peculiarity of current Omd versions is that insignificant square brackets still force it emit a text node, so any text with anything in square brackets will produce three nodes instead of one. It doesn't change escaping logic, however.

utop # Omd.of_string "[text in brackets]" ;;
- : Omd.doc =
[Omd.Paragraph ([],
  Omd.Concat ([],
   [Omd.Text ([], "["); Omd.Text ([], "text in brackets"); Omd.Text ([], "]")]))]

With my patch it seems to behave as expected:

$ echo 'Text with [square brackets], {braces}, and @-characters' | ./_build/default/src/md2mld.exe
Text with \[square brackets\], \{braces\}, and \@-characters

(Stdin reading support is from #8)

@mseri
Copy link
Owner

mseri commented Oct 2, 2022

Thanks! As the other I’ll wait for ci to finish. I will make a new release in the next few days

@dmbaturin dmbaturin force-pushed the square-bracket-escape branch from 68fb1f1 to b14dabb Compare October 2, 2022 08:30
@dmbaturin dmbaturin force-pushed the square-bracket-escape branch from b14dabb to 3e9c32c Compare October 2, 2022 08:46
@dmbaturin
Copy link
Contributor Author

Thanks! As the other I’ll wait for ci to finish. I will make a new release in the next few days

Tests fail because of ocp-indent errors at the dune build @fmt stage, and the problem is that it fails on your original code, so that code needs to be reformatted before the CI run can succeed.

How should we go about it? Shall I make a separate PR for formatting fixes and rebase these two PRs to that new branch?

@mseri
Copy link
Owner

mseri commented Oct 2, 2022

I should probably fix a ocaml format version. Let’s not worry about that

@mseri
Copy link
Owner

mseri commented Oct 2, 2022

I’ll fix it manually before release tomorrow or on Tuesday

@mseri mseri merged commit 2fb995c into mseri:master Oct 2, 2022
@dmbaturin
Copy link
Contributor Author

@mseri I also wanted to add a --version option before the next release. I'm not sure what would be your preferred approach to storing the option, though — whether you are fine with a hardcoded constant or you prefer cppo or similar.

@mseri
Copy link
Owner

mseri commented Oct 2, 2022

We can use dune subst mechanism I think

mseri added a commit to mseri/opam-repository that referenced this pull request Oct 3, 2022
CHANGES:

- Add support for `-version` option ([mseri/md2mld#10](mseri/md2mld#10) dmbaturin)
- Escape square brackets, braces and `@` characters in text nodes, fixes [mseri/md2mld#4](mseri/md2mld#4) ([mseri/md2mld#9](mseri/md2mld#9) dmbaturin)
- Add support for reading Markdown from the standard input ([mseri/md2mld#8](mseri/md2mld#8) dmbaturin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants