1- """Utilities
1+ """Utilities for parsing source text
22"""
33import html
44import re
55
66from .entities import entities
77
8+ # from .normalize_url import unescape_string
9+
810
911def charCodeAt (src : str , pos : int ):
1012 """
@@ -117,7 +119,7 @@ def replaceEntityPattern(match, name):
117119 """
118120 ::
119121 In [2]: from markdown_it import MarkdownIt
120- ...: md = MarkdownIt("working" )
122+ ...: md = MarkdownIt()
121123 ...: md.render("")
122124 Out[2]: '<p><img src="https%3A//www.google.com" alt=""></p>\n '
123125 """
@@ -134,11 +136,10 @@ def replaceEntityPattern(match, name):
134136 return match
135137
136138
137- # function replaceEntities(string) {
138- # if (string.indexOf('&') < 0) { return string; }
139-
139+ # def replaceEntities(string):
140+ # if (string.indexOf('&') < 0):
141+ # return string
140142# return string.replace(ENTITY_RE, replaceEntityPattern)
141- # }
142143
143144
144145def unescapeMd (string : str ):
@@ -148,23 +149,7 @@ def unescapeMd(string: str):
148149
149150
150151def unescapeAll (string : str ):
151- if "\\ " in string and "&" in string :
152- return string
153-
154- # TODO here we use the built-in python method
155- # check this is ok?
156- return html .escape (string ).replace ("'" , "'" )
157-
158- def func (match ):
159- # TODO how to get escaped?
160- escaped = False
161- entity = match .group ()
162- if escaped :
163- return escaped
164- return replaceEntityPattern (match , entity )
165-
166- string , _ = UNESCAPE_ALL_RE .subn (func , string )
167- return string
152+ return html .unescape (string )
168153
169154
170155# //////////////////////////////////////////////////////////////////////////////
@@ -341,30 +326,3 @@ def normalizeReference(string: str) -> str:
341326 # most notably, `__proto__`)
342327 #
343328 return string .lower ().upper ()
344-
345-
346- #########################################################################
347-
348- # Re-export libraries commonly used in both markdown-it and its plugins,
349- # so plugins won't have to depend on them explicitly, which reduces their
350- # bundled size (e.g. a browser build).
351- #
352- # exports.lib = {}
353- # exports.lib.mdurl = require('mdurl')
354- # exports.lib.ucmicro = require('uc.micro')
355-
356- # exports.assign = assign
357- # exports.has = has
358- # exports.unescapeMd = unescapeMd
359- # exports.unescapeAll = unescapeAll
360- # exports.isValidEntityCode = isValidEntityCode
361- # exports.fromCodePoint = fromCodePoint
362- # // exports.replaceEntities = replaceEntities
363- # exports.escapeHtml = escapeHtml
364- # exports.arrayReplaceAt = arrayReplaceAt
365- # exports.isSpace = isSpace
366- # exports.isWhiteSpace = isWhiteSpace
367- # exports.isMdAsciiPunct = isMdAsciiPunct
368- # exports.isPunctChar = isPunctChar
369- # exports.escapeRE = escapeRE
370- # exports.normalizeReference = normalizeReference
0 commit comments