From 9236cb0d7ebc02a3e81979679a46b32a79b9e87f Mon Sep 17 00:00:00 2001 From: Wouter Groeneveld Date: Fri, 13 Jan 2017 09:01:09 +0100 Subject: [PATCH] markdown links regex update --- .gitignore | 64 +++- .idea/dokuwiki-to-hugo.iml | 11 - .idea/misc.xml | 4 - .idea/modules.xml | 8 - .idea/workspace.xml | 710 ------------------------------------- src/markdown_links.py | 23 +- 6 files changed, 75 insertions(+), 745 deletions(-) delete mode 100644 .idea/dokuwiki-to-hugo.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index 05bfe41..6756caf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,60 @@ -# idea stuff -.idea/ +# Created by https://www.gitignore.io/api/pycharm,python + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml + +# Sensitive or high-churn files: +.idea/dataSources/ +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + + +### Python ### # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -23,6 +77,7 @@ lib64/ parts/ sdist/ var/ +wheels/ *.egg-info/ .installed.cfg *.egg @@ -69,7 +124,7 @@ docs/_build/ # PyBuilder target/ -# IPython Notebook +# Jupyter Notebook .ipynb_checkpoints # pyenv @@ -82,6 +137,7 @@ celerybeat-schedule .env # virtualenv +.venv/ venv/ ENV/ @@ -90,3 +146,5 @@ ENV/ # Rope project settings .ropeproject + +# End of https://www.gitignore.io/api/pycharm,python \ No newline at end of file diff --git a/.idea/dokuwiki-to-hugo.iml b/.idea/dokuwiki-to-hugo.iml deleted file mode 100644 index c8a7e47..0000000 --- a/.idea/dokuwiki-to-hugo.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index e714a9f..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index f22c1d7..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index c6b3515..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,710 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - contains - cont - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1484234851236 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/markdown_links.py b/src/markdown_links.py index 1cdef87..845f975 100644 --- a/src/markdown_links.py +++ b/src/markdown_links.py @@ -1,18 +1,23 @@ import os from os import walk - +import re class MarkdownLinks: known_shortcodes = ('wp') + pattern = re.compile('\[\[.+\]\]') def convert(self, text): - if not text.startswith("[["): - return text - if "http" in text or "www" in text: - return self.convert_as_external_link(text) - if ">" in text: - return self.convert_as_interwiki_link(text) - return self.convert_as_internal_link(text) + result = text + for link in MarkdownLinks.pattern.findall(text): + convertedlink = "" + if "http" in text or "www" in text: + convertedlink = self.convert_as_external_link(text) + elif ">" in text: + convertedlink = self.convert_as_interwiki_link(text) + else: + convertedlink = self.convert_as_internal_link(text) + result = result.replace(link, convertedlink) + return result def parseUrl(self, text): return text[2:text.index('|')] @@ -21,7 +26,7 @@ class MarkdownLinks: return text[2:len(text)-2].replace(":", "/") def parseTitle(self, text): - return text[text.index('|') + 1: text.index(']]') - 2] + return text[text.index('|') + 1: text.index(']]')] def convert_as_interwiki_link(self, text): interwiki_shortcode = text[2:text.index('>')]