paul@35 | 1 | #!/usr/bin/env python |
paul@35 | 2 | |
paul@35 | 3 | """ |
paul@35 | 4 | Common parsing data. |
paul@35 | 5 | |
paul@35 | 6 | Copyright (C) 2012, 2013 Paul Boddie <paul@boddie.org.uk> |
paul@35 | 7 | |
paul@35 | 8 | This software is free software; you can redistribute it and/or |
paul@35 | 9 | modify it under the terms of the GNU General Public License as |
paul@35 | 10 | published by the Free Software Foundation; either version 2 of |
paul@35 | 11 | the License, or (at your option) any later version. |
paul@35 | 12 | |
paul@35 | 13 | This software is distributed in the hope that it will be useful, |
paul@35 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@35 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@35 | 16 | GNU General Public License for more details. |
paul@35 | 17 | |
paul@35 | 18 | You should have received a copy of the GNU General Public |
paul@35 | 19 | License along with this library; see the file LICENCE.txt |
paul@35 | 20 | If not, write to the Free Software Foundation, Inc., |
paul@35 | 21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paul@35 | 22 | """ |
paul@35 | 23 | |
paul@84 | 24 | MAX_TITLE_LENGTH = 120 |
paul@84 | 25 | |
paul@35 | 26 | URL_SCHEMES = ("http", "https", "ftp", "mailto") |
paul@35 | 27 | |
paul@35 | 28 | # Translation helpers. |
paul@35 | 29 | |
paul@35 | 30 | blocktypes = { |
paul@35 | 31 | "h1" : "= %s =", |
paul@35 | 32 | "h2" : "== %s ==", |
paul@35 | 33 | "h3" : "=== %s ===", |
paul@35 | 34 | "h4" : "==== %s ====", |
paul@35 | 35 | "h5" : "===== %s =====", |
paul@35 | 36 | "h6" : "====== %s ======", |
paul@35 | 37 | "bq" : "{{{%s}}}", |
paul@35 | 38 | } |
paul@35 | 39 | |
paul@71 | 40 | headings = blocktypes.keys(); headings.remove("bq") |
paul@71 | 41 | |
paul@84 | 42 | def get_page_title(title): |
paul@84 | 43 | return title[:MAX_TITLE_LENGTH].strip() |
paul@84 | 44 | |
paul@71 | 45 | def quote_macro_argument(arg): |
paul@79 | 46 | if arg.find('"') != -1: |
paul@79 | 47 | return '"%s"' % arg.replace('"', '""') |
paul@79 | 48 | else: |
paul@79 | 49 | return arg |
paul@71 | 50 | |
paul@35 | 51 | # vim: tabstop=4 expandtab shiftwidth=4 |