Bläddra i källkod

Merge pull request #518 from wilsonfreitas/rmd

rmd_reader updated to use MarkdownReader's default settings
Justin Mayer 9 år sedan
förälder
incheckning
232ff3ae2f
2 ändrade filer med 17 tillägg och 13 borttagningar
  1. 15 2
      rmd_reader/Readme.md
  2. 2 11
      rmd_reader/rmd_reader.py

+ 15 - 2
rmd_reader/Readme.md

@@ -4,7 +4,20 @@ This plugin helps you creating posts with knitr's RMarkdown files.
 [knitr](http://yihui.name/knitr/) is a template engine which executes and displays embedded R code.
 [knitr](http://yihui.name/knitr/) is a template engine which executes and displays embedded R code.
 So, being short you can write an executable paper with codes, formulas and graphics.
 So, being short you can write an executable paper with codes, formulas and graphics.
 
 
-## Dependencies
+## Loading
+
+It is a good idea to load `rmd_reader` at last.
+It uses settings loaded at runtime and it is important to be sure that all settings have been loaded.
+
+```
+PLUGINS = ['sitemap',
+           'summary',
+           ...
+           'render_math',
+           'rmd_reader']  # put it here!
+```
+
+## Dependency
 
 
 This plugin needs [rpy2](https://pypi.python.org/pypi/rpy2) to work.
 This plugin needs [rpy2](https://pypi.python.org/pypi/rpy2) to work.
 Install it with:
 Install it with:
@@ -24,7 +37,7 @@ R> install.packages('knitr')
 
 
 The plugin detects RMD files ending with `.Rmd` or `.rmd` so you only have to write a RMarkdown files inside `content` directory.
 The plugin detects RMD files ending with `.Rmd` or `.rmd` so you only have to write a RMarkdown files inside `content` directory.
 
 
-This plugin calls R to process these files and generates markdown files that are processed by Python Markdown (with `meta`, `codehilite(css_class=highlight)`, and `extra` extensions) before returning the content and metadata to pelican engine.
+This plugin calls R to process these files and generates markdown files that are processed by Pelican's `MarkdownReader` in order to generate html files from ordinary `.md` files.
 
 
 ### Plotting
 ### Plotting
 
 

+ 2 - 11
rmd_reader/rmd_reader.py

@@ -15,7 +15,6 @@ except ImportError:
 
 
 class RmdReader(readers.BaseReader):
 class RmdReader(readers.BaseReader):
     enabled = rmd
     enabled = rmd
-
     file_extensions = ['Rmd', 'rmd']
     file_extensions = ['Rmd', 'rmd']
 
 
     # You need to have a read method, which takes a filename and returns
     # You need to have a read method, which takes a filename and returns
@@ -31,17 +30,9 @@ require(knitr);
 opts_knit$set(base.dir='{2}/content');
 opts_knit$set(base.dir='{2}/content');
 knit('{0}', '{1}', quiet=TRUE, encoding='UTF-8');
 knit('{0}', '{1}', quiet=TRUE, encoding='UTF-8');
 """.format(filename, md_filename, settings.DEFAULT_CONFIG.get('PATH')))
 """.format(filename, md_filename, settings.DEFAULT_CONFIG.get('PATH')))
-        # parse md file
-        md = Markdown(extensions = ['meta', 'codehilite(css_class=highlight)', 'extra'])
-        with pelican_open(md_filename) as text:
-            content = md.convert(text)
+        md_reader = readers.MarkdownReader(self.settings)
+        content, metadata = md_reader.read(md_filename)
         os.remove(md_filename)
         os.remove(md_filename)
-        # find metadata
-        metadata = {}
-        for name, value in md.Meta.items():
-            name = name.lower()
-            meta = self.process_metadata(name, value[0])
-            metadata[name] = meta
         return content, metadata
         return content, metadata
 
 
 def add_reader(readers):
 def add_reader(readers):