[Question] Processing single quotes after SmartyPants #117

Open
opened 2026-01-29 14:27:37 +00:00 by claunia · 4 comments
Owner

Originally created by @cincuranet on GitHub (Jul 2, 2017).

I'm trying to convert all single quotes left after SmartyPants extension into (’), but I'm failing. Whenever I introduce some LiteralInline into processor while in Match method, I erase everything what SmartyPants did. I think I need bit help where to properly plug the extension and how to match the char. Because so far all my attempts with my InlineParser failed.

This code:

Markdown.ToHtml("\"hello' test\"", pipeline);

returns <p>&ldquo;hello' test&rdquo;</p> (with SmartyPants). So far so good. What I'd like to archieve is to get <p>&ldquo;hello&rsquo; test&rdquo;</p> (or <p>&ldquo;hello’ test&rdquo;</p>).

Thanks for any kick in right direction.

Originally created by @cincuranet on GitHub (Jul 2, 2017). I'm trying to convert all single quotes left after _SmartyPants_ extension into `’` (`&rsquo;`), but I'm failing. Whenever I introduce some `LiteralInline` into `processor` while in `Match` method, I erase everything what _SmartyPants_ did. I think I need bit help where to properly plug the extension and how to match the char. Because so far all my attempts with my `InlineParser` failed. This code: ``` Markdown.ToHtml("\"hello' test\"", pipeline); ``` returns `<p>&ldquo;hello' test&rdquo;</p>` (with _SmartyPants_). So far so good. What I'd like to archieve is to get `<p>&ldquo;hello&rsquo; test&rdquo;</p>` (or `<p>&ldquo;hello’ test&rdquo;</p>`). Thanks for any kick in right direction.
claunia added the questionenhancement labels 2026-01-29 14:27:37 +00:00
Author
Owner

@xoofx commented on GitHub (Jul 2, 2017):

Not sure that would be easy to do it outside the existing extensions that already process these characters. I would start to modify the code at SmartyPantsInlineParser:L282 to keep the characters you want based on the criteria you are expecting...

@xoofx commented on GitHub (Jul 2, 2017): Not sure that would be easy to do it outside the existing extensions that already process these characters. I would start to modify the code at [`SmartyPantsInlineParser:L282`](https://github.com/lunet-io/markdig/blob/9906a0554fa0d07a21e6d1fedb0c04743ea58596/src/Markdig/Extensions/SmartyPants/SmartyPantsInlineParser.cs#L282) to keep the characters you want based on the criteria you are expecting...
Author
Owner

@cincuranet commented on GitHub (Jul 3, 2017):

Hmm. SmartyPants is using OpeningCharacters while my ' can be anywhere (see my example). Your idea of directly changing the parser is good. I can disable then the balancing checking.

@cincuranet commented on GitHub (Jul 3, 2017): Hmm. _SmartyPants_ is using `OpeningCharacters` while my `'` can be anywhere (see my example). Your idea of directly changing the parser is good. I can disable then the balancing checking.
Author
Owner

@xoofx commented on GitHub (Jul 3, 2017):

The OpeningCharacters is just used to indicate that the parser must be called for this character, but it can happen anywhere, that's fine. You just have to change slightly the behavior in the method BlockOnProcessInlinesEnd to better handle your case.

@xoofx commented on GitHub (Jul 3, 2017): The `OpeningCharacters` is just used to indicate that the parser must be called for this character, but it can happen anywhere, that's fine. You just have to change slightly the behavior in the method `BlockOnProcessInlinesEnd` to better handle your case.
Author
Owner

@cincuranet commented on GitHub (Jul 11, 2017):

Finally somewhat hacked it together. There's not much changes at the end. Here's the diff (some whitespaces are fucked up, I know): 192b875055 .

Not sure whether it's too far from original SmartyPants idea or not and hence some PR would be worth.

@cincuranet commented on GitHub (Jul 11, 2017): Finally somewhat hacked it together. There's not much changes at the end. Here's the diff (some whitespaces are fucked up, I know): https://github.com/cincuranet/markdig/commit/192b875055f349b58057fa8f1582581d97cedfb5?w=1 . Not sure whether it's too far from original _SmartyPants_ idea or not and hence some PR would be worth.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#117