mirror of
https://github.com/gryf/jekyll-rst.git
synced 2025-12-19 04:20:21 +01:00
Clean up transform code
This commit is contained in:
24
transform.py
24
transform.py
@@ -1,14 +1,17 @@
|
|||||||
|
import optparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from docutils.core import publish_parts
|
from docutils.core import publish_parts
|
||||||
from optparse import OptionParser
|
from docutils.frontend import OptionParser
|
||||||
from docutils.frontend import OptionParser as DocutilsOptionParser
|
|
||||||
from docutils.parsers.rst import Parser
|
from docutils.parsers.rst import Parser
|
||||||
|
|
||||||
|
|
||||||
def transform(writer=None, part=None):
|
def transform(writer=None, part=None):
|
||||||
p = OptionParser(add_help_option=False)
|
p = optparse.OptionParser(add_help_option=False)
|
||||||
|
|
||||||
# Collect all the command line options
|
# Collect all the command line options
|
||||||
docutils_parser = DocutilsOptionParser(components=(writer, Parser()))
|
docutils_parser = OptionParser(components=(writer, Parser()))
|
||||||
|
|
||||||
for group in docutils_parser.option_groups:
|
for group in docutils_parser.option_groups:
|
||||||
p.add_option_group(group.title, None).add_options(group.option_list)
|
p.add_option_group(group.title, None).add_options(group.option_list)
|
||||||
|
|
||||||
@@ -16,10 +19,8 @@ def transform(writer=None, part=None):
|
|||||||
|
|
||||||
opts, args = p.parse_args()
|
opts, args = p.parse_args()
|
||||||
|
|
||||||
settings = dict({
|
settings = dict({'file_insertion_enabled': False,
|
||||||
'file_insertion_enabled': False,
|
'raw_enabled': False}, **opts.__dict__)
|
||||||
'raw_enabled': False,
|
|
||||||
}, **opts.__dict__)
|
|
||||||
|
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
try:
|
try:
|
||||||
@@ -29,11 +30,8 @@ def transform(writer=None, part=None):
|
|||||||
else:
|
else:
|
||||||
content = sys.stdin.read()
|
content = sys.stdin.read()
|
||||||
|
|
||||||
parts = publish_parts(
|
parts = publish_parts(source=content, settings_overrides=settings,
|
||||||
source=content,
|
writer=writer)
|
||||||
settings_overrides=settings,
|
|
||||||
writer=writer,
|
|
||||||
)
|
|
||||||
|
|
||||||
if opts.part in parts:
|
if opts.part in parts:
|
||||||
return parts[opts.part]
|
return parts[opts.part]
|
||||||
|
|||||||
Reference in New Issue
Block a user