##// END OF EJS Templates
minirst: CGI escape strings prior to embedding it in the HTML
Dan Villiom Podlaski Christiansen -
r18750:c9d923f5 default
parent child Browse files
Show More
@@ -22,6 +22,8 b' import re'
22 22 import util, encoding
23 23 from i18n import _
24 24
25 import cgi
26
25 27 def section(s):
26 28 return "%s\n%s\n\n" % (s, "\"" * encoding.colwidth(s))
27 29
@@ -524,6 +526,9 b' def formathtml(blocks):'
524 526 headernest = ''
525 527 listnest = []
526 528
529 def escape(s):
530 return cgi.escape(s, True)
531
527 532 def openlist(start, level):
528 533 if not listnest or listnest[-1][0] != start:
529 534 listnest.append((start, level))
@@ -537,34 +542,34 b' def formathtml(blocks):'
537 542 lines = b['lines']
538 543
539 544 if btype == 'admonition':
540 admonition = _admonitiontitles[b['admonitiontitle']]
541 text = ' '.join(map(str.strip, lines))
545 admonition = escape(_admonitiontitles[b['admonitiontitle']])
546 text = escape(' '.join(map(str.strip, lines)))
542 547 out.append('<p>\n<b>%s</b> %s\n</p>\n' % (admonition, text))
543 548 elif btype == 'paragraph':
544 out.append('<p>\n%s\n</p>\n' % '\n'.join(lines))
549 out.append('<p>\n%s\n</p>\n' % escape('\n'.join(lines)))
545 550 elif btype == 'margin':
546 551 pass
547 552 elif btype == 'literal':
548 out.append('<pre>\n%s\n</pre>\n' % '\n'.join(lines))
553 out.append('<pre>\n%s\n</pre>\n' % escape('\n'.join(lines)))
549 554 elif btype == 'section':
550 555 i = b['underline']
551 556 if i not in headernest:
552 557 headernest += i
553 558 level = headernest.index(i) + 1
554 out.append('<h%d>%s</h%d>\n' % (level, lines[0], level))
559 out.append('<h%d>%s</h%d>\n' % (level, escape(lines[0]), level))
555 560 elif btype == 'table':
556 561 table = b['table']
557 562 t = []
558 563 for row in table:
559 564 l = []
560 for v in zip(row):
561 l.append('<td>%s</td>' % v)
565 for v in row:
566 l.append('<td>%s</td>' % escape(v))
562 567 t.append(' <tr>%s</tr>\n' % ''.join(l))
563 568 out.append('<table>\n%s</table>\n' % ''.join(t))
564 569 elif btype == 'definition':
565 570 openlist('dl', level)
566 term = lines[0]
567 text = ' '.join(map(str.strip, lines[1:]))
571 term = escape(lines[0])
572 text = escape(' '.join(map(str.strip, lines[1:])))
568 573 out.append(' <dt>%s\n <dd>%s\n' % (term, text))
569 574 elif btype == 'bullet':
570 575 bullet, head = lines[0].split(' ', 1)
@@ -572,16 +577,16 b' def formathtml(blocks):'
572 577 openlist('ul', level)
573 578 else:
574 579 openlist('ol', level)
575 out.append(' <li> %s\n' % ' '.join([head] + lines[1:]))
580 out.append(' <li> %s\n' % escape(' '.join([head] + lines[1:])))
576 581 elif btype == 'field':
577 582 openlist('dl', level)
578 key = b['key']
579 text = ' '.join(map(str.strip, lines))
583 key = escape(b['key'])
584 text = escape(' '.join(map(str.strip, lines)))
580 585 out.append(' <dt>%s\n <dd>%s\n' % (key, text))
581 586 elif btype == 'option':
582 587 openlist('dl', level)
583 opt = b['optstr']
584 desc = ' '.join(map(str.strip, lines))
588 opt = escape(b['optstr'])
589 desc = escape(' '.join(map(str.strip, lines)))
585 590 out.append(' <dt>%s\n <dd>%s\n' % (opt, desc))
586 591
587 592 # close lists if indent level of next block is lower
@@ -1519,7 +1519,7 b' Dish up an empty repo; serve it cold.'
1519 1519 </p>
1520 1520 <p>
1521 1521 The files will be added to the repository at the next commit. To
1522 undo an add before that, see "hg forget".
1522 undo an add before that, see &quot;hg forget&quot;.
1523 1523 </p>
1524 1524 <p>
1525 1525 If no names are given, add all files to the repository.
@@ -1633,8 +1633,8 b' Dish up an empty repo; serve it cold.'
1633 1633 </p>
1634 1634 <p>
1635 1635 This command schedules the files to be removed at the next commit.
1636 To undo a remove before that, see "hg revert". To undo added
1637 files, see "hg forget".
1636 To undo a remove before that, see &quot;hg revert&quot;. To undo added
1637 files, see &quot;hg forget&quot;.
1638 1638 </p>
1639 1639 <p>
1640 1640 Returns 0 on success, 1 if any warnings encountered.
@@ -1754,20 +1754,20 b' Dish up an empty repo; serve it cold.'
1754 1754 Any other string is treated as a bookmark, tag, or branch name. A
1755 1755 bookmark is a movable pointer to a revision. A tag is a permanent name
1756 1756 associated with a revision. A branch name denotes the tipmost revision
1757 of that branch. Bookmark, tag, and branch names must not contain the ":"
1757 of that branch. Bookmark, tag, and branch names must not contain the &quot;:&quot;
1758 1758 character.
1759 1759 </p>
1760 1760 <p>
1761 The reserved name "tip" always identifies the most recent revision.
1761 The reserved name &quot;tip&quot; always identifies the most recent revision.
1762 1762 </p>
1763 1763 <p>
1764 The reserved name "null" indicates the null revision. This is the
1764 The reserved name &quot;null&quot; indicates the null revision. This is the
1765 1765 revision of an empty repository, and the parent of revision 0.
1766 1766 </p>
1767 1767 <p>
1768 The reserved name "." indicates the working directory parent. If no
1768 The reserved name &quot;.&quot; indicates the working directory parent. If no
1769 1769 working directory is checked out, it is equivalent to null. If an
1770 uncommitted merge is in progress, "." is the revision of the first
1770 uncommitted merge is in progress, &quot;.&quot; is the revision of the first
1771 1771 parent.
1772 1772 </p>
1773 1773
@@ -605,7 +605,7 b' Please see "hg add".'
605 605 html format:
606 606 ----------------------------------------------------------------------
607 607 <p>
608 Please see "hg add".
608 Please see &quot;hg add&quot;.
609 609 </p>
610 610 ----------------------------------------------------------------------
611 611
@@ -645,7 +645,7 b' html format:'
645 645 <h1>Title</h1>
646 646 <h2>Section</h2>
647 647 <h3>Subsection</h3>
648 <h2>Markup: "foo" and "hg help"</h2>
648 <h2>Markup: &quot;foo&quot; and &quot;hg help&quot;</h2>
649 649 ----------------------------------------------------------------------
650 650
651 651 == admonitions ==
General Comments 0
You need to be logged in to leave comments. Login now