##// END OF EJS Templates
markdown: improved styling, and fixed nl2br extensions to only do br on new elements not inline....
milka -
r4533:74d334b4 default
parent child Browse files
Show More
@@ -67,7 +67,7 b' markdown_tags = ['
67 67
68 68 markdown_attrs = {
69 69 "*": ["class", "style", "align"],
70 "img": ["src", "alt", "title"],
70 "img": ["src", "alt", "title", "width", "height", "hspace", "align"],
71 71 "a": ["href", "alt", "title", "name", "data-hovercard-alt", "data-hovercard-url"],
72 72 "abbr": ["title"],
73 73 "acronym": ["title"],
@@ -18,17 +18,85 b''
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 import re
21 22 import markdown
23 import xml.etree.ElementTree as etree
22 24
23 25 from markdown.extensions import Extension
24 26 from markdown.extensions.fenced_code import FencedCodeExtension
25 27 from markdown.extensions.smart_strong import SmartEmphasisExtension
26 28 from markdown.extensions.tables import TableExtension
27 from markdown.extensions.nl2br import Nl2BrExtension
29 from markdown.inlinepatterns import Pattern
28 30
29 31 import gfm
30 32
31 33
34 class InlineProcessor(Pattern):
35 """
36 Base class that inline patterns subclass.
37 This is the newer style inline processor that uses a more
38 efficient and flexible search approach.
39 """
40
41 def __init__(self, pattern, md=None):
42 """
43 Create an instant of an inline pattern.
44 Keyword arguments:
45 * pattern: A regular expression that matches a pattern
46 """
47 self.pattern = pattern
48 self.compiled_re = re.compile(pattern, re.DOTALL | re.UNICODE)
49
50 # Api for Markdown to pass safe_mode into instance
51 self.safe_mode = False
52 self.md = md
53
54 def handleMatch(self, m, data):
55 """Return a ElementTree element from the given match and the
56 start and end index of the matched text.
57 If `start` and/or `end` are returned as `None`, it will be
58 assumed that the processor did not find a valid region of text.
59 Subclasses should override this method.
60 Keyword arguments:
61 * m: A re match object containing a match of the pattern.
62 * data: The buffer current under analysis
63 Returns:
64 * el: The ElementTree element, text or None.
65 * start: The start of the region that has been matched or None.
66 * end: The end of the region that has been matched or None.
67 """
68 pass # pragma: no cover
69
70
71 class SimpleTagInlineProcessor(InlineProcessor):
72 """
73 Return element of type `tag` with a text attribute of group(2)
74 of a Pattern.
75 """
76 def __init__(self, pattern, tag):
77 InlineProcessor.__init__(self, pattern)
78 self.tag = tag
79
80 def handleMatch(self, m, data): # pragma: no cover
81 el = etree.Element(self.tag)
82 el.text = m.group(2)
83 return el, m.start(0), m.end(0)
84
85
86 class SubstituteTagInlineProcessor(SimpleTagInlineProcessor):
87 """ Return an element of type `tag` with no children. """
88 def handleMatch(self, m, data):
89 return etree.Element(self.tag), m.start(0), m.end(0)
90
91
92 class Nl2BrExtension(Extension):
93 BR_RE = r'\n'
94
95 def extendMarkdown(self, md, md_globals):
96 br_tag = SubstituteTagInlineProcessor(self.BR_RE, 'br')
97 md.inlinePatterns.add('nl', br_tag, '_end')
98
99
32 100 class GithubFlavoredMarkdownExtension(Extension):
33 101 """
34 102 An extension that is as compatible as possible with GitHub-flavored
@@ -51,6 +119,7 b' class GithubFlavoredMarkdownExtension(Ex'
51 119
52 120 def extendMarkdown(self, md, md_globals):
53 121 # Built-in extensions
122 Nl2BrExtension().extendMarkdown(md, md_globals)
54 123 FencedCodeExtension().extendMarkdown(md, md_globals)
55 124 SmartEmphasisExtension().extendMarkdown(md, md_globals)
56 125 TableExtension().extendMarkdown(md, md_globals)
@@ -68,7 +137,6 b' class GithubFlavoredMarkdownExtension(Ex'
68 137 gfm.TaskListExtension([
69 138 ('list_attrs', {'class': 'checkbox'})
70 139 ]).extendMarkdown(md, md_globals)
71 Nl2BrExtension().extendMarkdown(md, md_globals)
72 140
73 141
74 142 # Global Vars
@@ -213,7 +213,6 b' div.markdown-block pre {'
213 213 div.markdown-block img {
214 214 border-style: none;
215 215 background-color: #fff;
216 padding-right: 20px;
217 216 max-width: 100%;
218 217 }
219 218
@@ -274,6 +273,13 b' div.markdown-block #ws {'
274 273 background-color: @grey6;
275 274 }
276 275
276 div.markdown-block p {
277 margin-top: 0;
278 margin-bottom: 16px;
279 padding: 0;
280 line-height: unset;
281 }
282
277 283 div.markdown-block code,
278 284 div.markdown-block pre,
279 285 div.markdown-block #ws,
@@ -115,11 +115,9 b' div.readme_box pre {'
115 115 div.readme_box img {
116 116 border-style: none;
117 117 background-color: #fff;
118 padding-right: 20px;
119 118 max-width: 100%;
120 119 }
121 120
122
123 121 div.readme_box strong {
124 122 font-weight: 600;
125 123 margin: 0;
@@ -152,6 +150,13 b' div.readme_box a:visited {'
152 150 }
153 151 */
154 152
153 div.readme_box p {
154 margin-top: 0;
155 margin-bottom: 16px;
156 padding: 0;
157 line-height: unset;
158 }
159
155 160
156 161 div.readme_box button {
157 162 font-size: @basefontsize;
@@ -337,7 +337,6 b' text_monospace = "\'Menlo\', \'Liberation M'
337 337 div.markdown-block img {
338 338 border-style: none;
339 339 background-color: #fff;
340 padding-right: 20px;
341 340 max-width: 100%
342 341 }
343 342
@@ -395,6 +394,13 b' text_monospace = "\'Menlo\', \'Liberation M'
395 394 background-color: #eeeeee
396 395 }
397 396
397 div.markdown-block p {
398 margin-top: 0;
399 margin-bottom: 16px;
400 padding: 0;
401 line-height: unset;
402 }
403
398 404 div.markdown-block code,
399 405 div.markdown-block pre,
400 406 div.markdown-block #ws,
General Comments 0
You need to be logged in to leave comments. Login now