From: Waylan L. <way...@ic...> - 2016-04-06 19:32:11
|
Sorry for the delayed response. I found this message at the bottom of a long list of things waiting for me to write a reply. If you would like HTML entities to be escaped as well as HTML tags, then you can remove the `entity` inlinePattern. Just add the appropriate line to your Extension class: class EscapeHtml(Extension): def extendMarkdown(self, md, md_globals): del md.preprocessors['html_block'] del md.inlinePatterns['html'] del md.inlinePatterns['entity'] Hope that helps. Waylan Limberg On Mar 25, 2016, at 11:57 AM, Dr Rainer Woitok <rai...@gm...> wrote: Greetings, in the release notes for version 2.6 I found the following workaround for the former "save_mode='escape'" option: $ cat test #! /usr/bin/env python # -*- coding: iso-8859-1 -*- import markdown from markdown.extensions import Extension class EscapeHtml(Extension): def extendMarkdown(self, md, md_globals): del md.preprocessors['html_block'] del md.inlinePatterns['html'] print markdown.markdown('<&>:& becomes &', extensions=[EscapeHtml()]) $ ./test <p><&>:& becomes &</p> $ However, I would expect the output to be <p><&>:& becomes &amp;</p> and that is also what the former "save_mode='escape'" did. Is there an easy way to modify the above "EscapeHtml" extension so it will also esc- ape the "&" in "&"? Any pointers appreciated. Sincerely, Rainer ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140 _______________________________________________ Python-markdown-discuss mailing list Pyt...@li... https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss |
From: Dr R. W. <rai...@gm...> - 2016-04-07 13:41:19
|
Waylan, On Wednesday, 2016-04-06 18:31:57 +0000, you wrote: > ... > If you would like HTML entities to be escaped as well as HTML tags, then you can remove the `entity` inlinePattern. Just add the appropriate line to your Extension class: > > class EscapeHtml(Extension): > def extendMarkdown(self, md, md_globals): > del md.preprocessors['html_block'] > del md.inlinePatterns['html'] > del md.inlinePatterns['entity'] > > Hope that helps. Works like a charme, thankyou :-) Sincerely, Rainer |
From: Dr R. W. <rai...@gm...> - 2019-01-15 11:58:38
|
Waylan, On Wednesday, 2016-04-06 18:31:57 +0000, you wrote: > ... > If you would like HTML entities to be escaped as well as HTML tags, then you can remove the `entity` inlinePattern. Just add the appropriate line to your Extension class: > > class EscapeHtml(Extension): > def extendMarkdown(self, md, md_globals): > del md.preprocessors['html_block'] > del md.inlinePatterns['html'] > del md.inlinePatterns['entity'] > > Hope that helps. This was 2.75 years ago and it solved my problem, which was: > ... > On Mar 25, 2016, at 11:57 AM, Dr Rainer Woitok <rai...@gm...> wrote: > ... > $ cat test > #! /usr/bin/env python > # -*- coding: iso-8859-1 -*- > > import markdown > from markdown.extensions import Extension > > class EscapeHtml(Extension): > def extendMarkdown(self, md, md_globals): > del md.preprocessors['html_block'] > del md.inlinePatterns['html'] > > print markdown.markdown('<&>:& becomes &', extensions=[EscapeHtml()]) > $ ./test > <p><&>:& becomes &</p> > $ > > However, I would expect the output to be > > <p><&>:& becomes &amp;</p> More precisely, it at least worked until changeset "81fb14216e8c" (dated 2018-06-28 23:33:34 +0300) in the source repository. However, after re- installing Markdown from changeset "596be577c69c" (dated 2018-12-22 15: 51:30 -0500) and re-running my little test script I'm now again getting <p><&>:& becomes &</p> What do I have to change this time? Sincerely, Rainer |
From: Waylan L. <way...@ic...> - 2019-01-20 20:36:40
|
This was part of the changes <https://python-markdown.github.io/change_log/release-3.0/#homegrown-ordereddict-has-been-replaced-with-a-purpose-built-registry> to version 3.0. You should use deregister <https://python-markdown.github.io/extensions/api/#registry.deregister>: class EscapeHTML(Extension): def extendMarkdown(self, md, md_globals): md.preprocessors.deregister(‘html_block’) md.inlinePatterns.deregister(‘html’) md.inlinePatterns.deregister(‘entity’) Waylan Limberg > On Jan 15, 2019, at 6:58 AM, Dr Rainer Woitok <rai...@gm...> wrote: > > Waylan, > > On Wednesday, 2016-04-06 18:31:57 +0000, you wrote: > >> ... >> If you would like HTML entities to be escaped as well as HTML tags, then you can remove the `entity` inlinePattern. Just add the appropriate line to your Extension class: >> >> class EscapeHtml(Extension): >> def extendMarkdown(self, md, md_globals): >> del md.preprocessors['html_block'] >> del md.inlinePatterns['html'] >> del md.inlinePatterns['entity'] >> >> Hope that helps. > > This was 2.75 years ago and it solved my problem, which was: > >> ... >> On Mar 25, 2016, at 11:57 AM, Dr Rainer Woitok <rai...@gm... <mailto:rai...@gm...>> wrote: >> ... >> $ cat test >> #! /usr/bin/env python >> # -*- coding: iso-8859-1 -*- >> >> import markdown >> from markdown.extensions import Extension >> >> class EscapeHtml(Extension): >> def extendMarkdown(self, md, md_globals): >> del md.preprocessors['html_block'] >> del md.inlinePatterns['html'] >> >> print markdown.markdown('<&>:& becomes &', extensions=[EscapeHtml()]) >> $ ./test >> <p><&>:& becomes &</p> >> $ >> >> However, I would expect the output to be >> >> <p><&>:& becomes &amp;</p> > > More precisely, it at least worked until changeset "81fb14216e8c" (dated > 2018-06-28 23:33:34 +0300) in the source repository. However, after re- > installing Markdown from changeset "596be577c69c" (dated 2018-12-22 15: > 51:30 -0500) and re-running my little test script I'm now again getting > > <p><&>:& becomes &</p> > > What do I have to change this time? > > Sincerely, > Rainer > > > _______________________________________________ > Python-markdown-discuss mailing list > Pyt...@li... <mailto:Pyt...@li...> > https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss <https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss> |
From: Dr R. W. <rai...@gm...> - 2019-01-22 13:18:05
|
Waylan, On Sunday, 2019-01-20 15:35:57 -0500, you wrote: > ... > class EscapeHTML(Extension): > def extendMarkdown(self, md, md_globals): > md.preprocessors.deregister(‘html_block’) > md.inlinePatterns.deregister(‘html’) > md.inlinePatterns.deregister(‘entity’) This time this didn't help: $ cat test.py # -*- coding: iso-8859-1 -*- import markdown from markdown.extensions import Extension class EscapeHtml(Extension): def extendMarkdown(self, md, md_globals): md.inlinePatterns.deregister('entity') md.inlinePatterns.deregister('html') md.preprocessors.deregister('html_block') print(markdown.__version__) print(markdown.markdown('<&>:& becomes &', extensions=[EscapeHtml()])) $ python test.py 3.1.dev0 <p><&>:& becomes &</p> $ However, I need _EVERY_ "&" in the original Markdown text to be trans- lated to "&" in the HTML file. Thus the raw text "becomes &" should be turned into "becomes &amp;". How can I achieve this in version 3.0 and up? At least with Markdown version 2.6.10 and lower removing "entity" from "inlinePatterns" really did the trick, but not so in 3.0 and above. Sincerely, Rainer |
From: Waylan L. <way...@ic...> - 2019-01-31 00:29:13
|
Ah, I see your problem. The change was introduced in #670 <https://github.com/Python-Markdown/markdown/pull/670>. The thinking behind that change was that we should only escape things which have not already been escaped. Of course, `&` is already an HTML entity so it is escaped and should not be escaped a second time. However, the actual escaping happens in the serializer, not in the `entity` inline pattern. Therefore the behavior of the serializer was changed to never escape `@amp;. Removing the inline pattern has no effect on this behavior. I do not see any good reason to alter the current behavior of the serializer either. It’s not clear to me how you should proceed. Although, I did question the method we used to accomplish the change in #670 (as you can see in the comments there). Perhaps there is another way we could accomplish the same effect that would better meet your needs as well. I would suggest opening a new issue in GitHub to discuss any possible future changes to the code. Waylan Limberg > On Jan 15, 2019, at 6:58 AM, Dr Rainer Woitok <rai...@gm...> wrote: > > Waylan, > > On Wednesday, 2016-04-06 18:31:57 +0000, you wrote: > >> ... >> If you would like HTML entities to be escaped as well as HTML tags, then you can remove the `entity` inlinePattern. Just add the appropriate line to your Extension class: >> >> class EscapeHtml(Extension): >> def extendMarkdown(self, md, md_globals): >> del md.preprocessors['html_block'] >> del md.inlinePatterns['html'] >> del md.inlinePatterns['entity'] >> >> Hope that helps. > > This was 2.75 years ago and it solved my problem, which was: > >> ... >> On Mar 25, 2016, at 11:57 AM, Dr Rainer Woitok <rai...@gm... <mailto:rai...@gm...>> wrote: >> ... >> $ cat test >> #! /usr/bin/env python >> # -*- coding: iso-8859-1 -*- >> >> import markdown >> from markdown.extensions import Extension >> >> class EscapeHtml(Extension): >> def extendMarkdown(self, md, md_globals): >> del md.preprocessors['html_block'] >> del md.inlinePatterns['html'] >> >> print markdown.markdown('<&>:& becomes &', extensions=[EscapeHtml()]) >> $ ./test >> <p><&>:& becomes &</p> >> $ >> >> However, I would expect the output to be >> >> <p><&>:& becomes &amp;</p> > > More precisely, it at least worked until changeset "81fb14216e8c" (dated > 2018-06-28 23:33:34 +0300) in the source repository. However, after re- > installing Markdown from changeset "596be577c69c" (dated 2018-12-22 15: > 51:30 -0500) and re-running my little test script I'm now again getting > > <p><&>:& becomes &</p> > > What do I have to change this time? > > Sincerely, > Rainer > > > _______________________________________________ > Python-markdown-discuss mailing list > Pyt...@li... <mailto:Pyt...@li...> > https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss <https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss> |
From: Dr R. W. <rai...@gm...> - 2019-02-12 17:14:26
|
Waylan, sorry for the late reply. On Wednesday, 2019-01-30 19:28:49 -0500, you wrote: > Ah, I see your problem. The change was introduced in #670 > <https://github.com/Python-Markdown/markdown/pull/670>. The thinking > behind that change was that we should only escape things which have > not already been escaped. Of course, `&` is already an HTML entity > so it is escaped and should not be escaped a second time. I slightly help maintaining the documentation of a project hosted at Bitbucket by providing a Python script which locally turns "*.md" files into *.html" files exactly the same way as Bitbucket would do. Accord- ing to Bitbucket they are using Python Markdown with save mode to escape any characters having a special meaning in HTML. To quote from our own Markdown file explaining how to write documentation: This is required because the _Markdown_ language implemented on the Bitbucket server does not pass any HTML entities like for instance "`&`", "`ê`", or the equivalent forms for the latter, "`ê`" and "`ê`", on to the HTML code. Rather it renders "`&`" into "`&amp;`" which will then again be displayed literally as "`&`" by your browser. And this is the HTML generated from the above Markdown source using a Markdown version slightly before #670: <p>This is required because the <em>Markdown</em> language implemented on the Bitbucket server does not pass any HTML entities like for instance "<code>&amp;</code>", "<code>&ecirc;</code>", or the equivalent forms for the latter, "<code>&#234;</code>" and "<code>&#x000EA;</code>", on to the HTML code. Rather it renders "<code>&amp;</code>" into "<code>&amp;amp;</code>" which will then again be displayed literally as "<code>&amp;</code>" by your browser. So all we are needing is a way to modify our "EscapeHtml" extension so that the above Markdown source is still turned into the above HTML text. > ... > I would suggest opening a new issue in GitHub > to discuss any possible future changes to the code. Yes, please do so. And do not hesitate to use the above Markdown and HTML examples as a rationale for this request. Sincerely, Rainer |