From 2f34307e129a8ae14b29262b9c63c0ab091f0f7f Mon Sep 17 00:00:00 2001 From: Talha Mansoor Date: Thu, 29 Aug 2013 23:14:47 +0500 Subject: [PATCH 1/4] Change the regex so that it parse |filename| and {filename} equally Updates getpelican/pelican#1061 --- pelican/contents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/contents.py b/pelican/contents.py index 900049a2..94790612 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -187,7 +187,7 @@ class Content(object): (?:href|src)\s*=) (?P["\']) # require value to be quoted - (?P\|(?P.*?)\|(?P.*?)) # the url value + (?P[|{](?P.*?)[|}](?P.*?)) # the url value \2""", re.X) def replacer(m): From bddf0faa9c616350a179864d26f0271c418554b5 Mon Sep 17 00:00:00 2001 From: Talha Mansoor Date: Thu, 29 Aug 2013 23:23:54 +0500 Subject: [PATCH 2/4] Update documentation to reflect change in intrasite link syntax Updates getpelican/pelican#1061 --- docs/getting_started.rst | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index bad9bbda..f9aa8d50 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -400,7 +400,7 @@ and images that may be sitting alongside the current post (instead of having to determine where those resources will be placed after site generation). To link to internal content (files in the ``content`` directory), use the -following syntax: ``|filename|path/to/file``:: +following syntax: ``{filename}path/to/file``:: website/ @@ -421,8 +421,8 @@ In this example, ``article1.rst`` could look like:: See below intra-site link examples in reStructuredText format. - `a link relative to content root <|filename|/cat/article2.rst>`_ - `a link relative to current file <|filename|cat/article2.rst>`_ + `a link relative to content root <{filename}/cat/article2.rst>`_ + `a link relative to current file <{filename}cat/article2.rst>`_ and ``article2.md``:: @@ -431,8 +431,8 @@ and ``article2.md``:: See below intra-site link examples in Markdown format. - [a link relative to content root](|filename|/article1.md) - [a link relative to current file](|filename|../article1.md) + [a link relative to content root]({filename}/article1.md) + [a link relative to current file]({filename}../article1.md) Embedding non-article or non-page content is slightly different in that the directories need to be specified in ``pelicanconf.py`` file. The ``images`` @@ -447,7 +447,7 @@ manually:: And ``image-test.md`` would include:: - ![Alt Text](|filename|/images/han.jpg) + ![Alt Text]({filename}/images/han.jpg) Any content can be linked in this way. What happens is that the ``images`` directory gets copied to ``output/static/`` upon publishing. This is @@ -459,9 +459,16 @@ following to ``pelicanconf.py``:: And then the ``pdfs`` directory would also be copied to ``output/static/``. -You can also link to categories or tags, using the `|tag|tagname` and -`|category|foobar` syntax. +You can also link to categories or tags, using the ``{tag}tagname`` and +``{category}foobar`` syntax. +For backward compatibility, Pelican also supports bars ``||``, besides ``{}``, +i.e. the ``filename``, ``tag`` and ``category`` identifiers can be enclosed +in bars ``|`` instead of braces ``{}``, for example, ``|filename|an_article.rst``, +``|tag|tagname``, ``|category|foobar``. + +Using ``{}`` ensures that the syntax will not collide with markdown extensions or +reST directives. Importing an existing blog -------------------------- From 48fa70c6a6112eb8722c9d3c7a892547c34312ae Mon Sep 17 00:00:00 2001 From: Talha Mansoor Date: Sun, 1 Sep 2013 00:35:13 +0500 Subject: [PATCH 3/4] Add INTRASITE_LINK_REGEX to configuration that user can modify This INTRASITE_LINK_REGEX is a string. It should have the capturing group name which is `what`. This change was made after discussions with @ametaireau and @justinmayer. 1. https://github.com/getpelican/pelican/pull/1067 1. https://github.com/getpelican/pelican/pull/1071 Updates getpelican/pelican#1061 --- pelican/contents.py | 8 +++++--- pelican/settings.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 94790612..b453f61b 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -182,13 +182,15 @@ class Content(object): if not content: return content - hrefs = re.compile(r""" + instrasite_link_regex = self.settings['INTRASITE_LINK_REGEX'] + regex = r""" (?P<\s*[^\>]* # match tag with src and href attr (?:href|src)\s*=) (?P["\']) # require value to be quoted - (?P[|{](?P.*?)[|}](?P.*?)) # the url value - \2""", re.X) + (?P{0}(?P.*?)) # the url value + \2""".format(instrasite_link_regex) + hrefs = re.compile(regex, re.X) def replacer(m): what = m.group('what') diff --git a/pelican/settings.py b/pelican/settings.py index 1f2646f6..1c2db677 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -110,6 +110,7 @@ DEFAULT_CONFIG = { 'TEMPLATE_PAGES': {}, 'IGNORE_FILES': ['.#*'], 'SLUG_SUBSTITUTIONS': (), + 'INTRASITE_LINK_REGEX': '[{|](?P.*?)[|}]', } From e2236d50d6efb7e5c0ef07098944851e4633c950 Mon Sep 17 00:00:00 2001 From: Talha Mansoor Date: Sun, 1 Sep 2013 01:01:25 +0500 Subject: [PATCH 4/4] Update settings documentation to explain INTRASITE_LINK_REGEX I have added reference to "Linking to internal content" section because without it, it is difficult to explain the usage. I have also updated changelog. Closes getpelican/pelican#1061 --- docs/changelog.rst | 3 ++- docs/getting_started.rst | 2 ++ docs/settings.rst | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 27938d4d..bbe0e76c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,7 +9,8 @@ Next release longer article-specific * Deprecate ``FILES_TO_COPY`` in favor of ``STATIC_PATHS`` and ``EXTRA_PATH_METADATA`` -* Add support for |tag| and |category| relative links. +* Add support for ``{}`` in relative links syntax, besides ``||`` +* Add support for |tag| and |category| relative links 3.2.1 and 3.2.2 =============== diff --git a/docs/getting_started.rst b/docs/getting_started.rst index f9aa8d50..d7a36080 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -390,6 +390,8 @@ If you want to exclude any pages from being linked to or listed in the menu then add a ``status: hidden`` attribute to its metadata. This is useful for things like making error pages that fit the generated theme of your site. +.. _ref-linking-to-internal-content: + Linking to internal content --------------------------- diff --git a/docs/settings.rst b/docs/settings.rst index c709a339..d021bcb0 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -156,6 +156,11 @@ Setting name (default value) What doe `_ `WITH_FUTURE_DATES` (``True``) If disabled, content with dates in the future will get a default status of draft. +`INTRASITE_LINK_REGEX` (``'[{|](?P.*?)[|}]'``) Regular expression that is used to parse internal links. + Default syntax of links to internal files, tags, etc. is + to enclose the identifier, say ``filename``, in ``{}`` or ``||``. + Identifier between ``{`` and ``}`` goes into the ``what`` capturing group. + For details see :ref:`ref-linking-to-internal-content`. ===================================================================== ===================================================================== .. [#] Default is the system locale.