Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: tools/md_browser/gitiles_smart_quotes.py

Issue 2740863004: support gitiles smart quoting (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/md_browser/md_browser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # -*- coding: utf-8 -*-
2 # Copyright 2017 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Implements Gitiles' smart quotes.
7
8 This extention converts dumb quotes into smart quotes like Gitiles:
9
10 https://gerrit.googlesource.com/gitiles/+/master/gitiles-servlet/src/main/java/c om/google/gitiles/doc/SmartQuotedExtension.java
11 """
12
13 from markdown.inlinepatterns import Pattern
14 from markdown.extensions import Extension
15
16
17 class _GitilesSmartQuotesPattern(Pattern):
18 """Process Gitiles' dumb->smart quotes."""
19
20 QUOTES = {
21 '"': (u'“', u'”'),
22 "'": (u'‘', u'’'),
23 }
24
25 def handleMatch(self, m):
26 lq, rq = self.QUOTES[m.group(2)]
27 return u'%s%s%s' % (lq, m.group(3), rq)
28
29
30 class _GitilesSmartQuotesExtension(Extension):
31 """Add Gitiles' smart quotes to Markdown."""
32 def extendMarkdown(self, md, md_globals):
33 md.inlinePatterns.add('gitilessmartquotes',
34 _GitilesSmartQuotesPattern(r"""(['"])([^\2]+)\2"""),
35 '<emphasis')
36
37
38 def makeExtension(*args, **kwargs):
39 return _GitilesSmartQuotesExtension(*args, **kwargs)
OLDNEW
« no previous file with comments | « no previous file | tools/md_browser/md_browser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698