From ced31cc4f4214d3cb8ca4e5882d51f6c6b796ce9 Mon Sep 17 00:00:00 2001 From: James Norman Date: Tue, 3 Sep 2013 21:32:24 +0100 Subject: [PATCH] Added ability to refernce metadata fields from within the markdown file. --- README.md | 12 ++++++++++++ bin/restdown | 3 +++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 3f418a6..f3d6d85 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,18 @@ Metadata can also be provided on the command-line with the `-d|--define` option. restdown --define mediaroot=/ index.restdown +## Using Metadata Fields + +You can also access the values of the metadata fields you set in your markdown as follows: + + --- + author: John Doe + created: 3rd September 2013 + --- + + The author of this document is #{author}. It was created on #{created}. + + # JSON API Summary diff --git a/bin/restdown b/bin/restdown index 930a9a1..cf03caf 100755 --- a/bin/restdown +++ b/bin/restdown @@ -269,6 +269,9 @@ def restdown(metadata, markdown, brand_dir=None, doc_dir=None): @returns {str, dict} The HTML document (full page) and a dict giving data about the API: version, endpoints. """ + for key in metadata: + markdown = re.sub(r"#{" + key + "}", metadata.get(key), markdown) + doc_markdown_opts = copy.deepcopy(markdown_opts) for extra in metadata.get("markdown2extras", []): doc_markdown_opts["extras"][extra] = True