aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-01-07 22:42:42 +0000
committerMichael Williamson <mike@zwobble.org>2014-01-07 22:42:42 +0000
commit629ce26f2b09bc4e93448d2c4f7a4cacb222f369 (patch)
treeab169bd0c84c5e3db21b673e01a9880aedd0075f
parent214689b8eb45302a0adea8006fb95b58156fb27e (diff)
Rename styles to style map for clarity
-rw-r--r--README.md8
-rw-r--r--mammoth/__init__.py10
-rw-r--r--scripts/mammoth16
3 files changed, 19 insertions, 15 deletions
diff --git a/README.md b/README.md
index bcebc0b..8a0dc1c 100644
--- a/README.md
+++ b/README.md
@@ -39,12 +39,12 @@ For instance:
#### Styles
-Custom styles can be read from a file using `--styles`.
+A custom style map can be read from a file using `--style-map`.
For instance:
- mammoth document.docx output.html --styles=custom-styles
+ mammoth document.docx output.html --style-map=custom-style-map
-Where `custom-styles` looks something like:
+Where `custom-style-map` looks something like:
p.AsideHeading => div.aside > h2:fresh
p.AsideText => div.aside > p:fresh
@@ -69,7 +69,7 @@ By default,
Mammoth maps some common .docx styles to HTML elements.
For instance,
a paragraph with the style `Heading1` is converted to a `h1` element.
-You can pass in a custom map for styles by passing an options object with a `styleMap` property as a second argument to `convertToHtml`.
+You can pass in custom styles using the `style_map` argument.
A description of the syntax for styles can be found in the section "Writing styles".
For instance, if paragraphs with the style `SectionTitle` should be converted to `h1` elements,
and paragraphs with the style `SubSectionTitle` should be converted to `h2` elements:
diff --git a/mammoth/__init__.py b/mammoth/__init__.py
index 65b8821..3c726d6 100644
--- a/mammoth/__init__.py
+++ b/mammoth/__init__.py
@@ -2,16 +2,16 @@ from .results import Result
from . import docx, conversion, style_reader, lists
-def convert_to_html(fileobj, styles=None, convert_image=None):
- if styles is None:
- styles = _default_styles
+def convert_to_html(fileobj, style_map=None, convert_image=None):
+ if style_map is None:
+ style_map = _default_styles
return docx.read(fileobj).bind(lambda document:
- conversion.convert_document_element_to_html(document, styles=_read_styles(styles), convert_image=convert_image)
+ conversion.convert_document_element_to_html(document, styles=_read_style_map(style_map), convert_image=convert_image)
)
-def _read_styles(style_text):
+def _read_style_map(style_text):
lines = filter(None, map(lambda line: line.strip(), style_text.split("\n")))
return lists.map(style_reader.read_style, lines)
diff --git a/scripts/mammoth b/scripts/mammoth
index 4f404ad..1b2fed1 100644
--- a/scripts/mammoth
+++ b/scripts/mammoth
@@ -12,11 +12,11 @@ import mammoth
def main():
args = _parse_args()
- if args.styles is None:
- styles = None
+ if args.style_map is None:
+ style_map = None
else:
- with open(args.styles) as styles_fileobj:
- styles = styles_fileobj.read()
+ with open(args.style_map) as style_map_fileobj:
+ style_map = style_map_fileobj.read()
with open(args.path, "rb") as docx_fileobj:
if args.output_dir is None:
@@ -27,7 +27,11 @@ def main():
output_filename = "{0}.html".format(os.path.basename(args.path).rpartition(".")[0])
output_path = os.path.join(args.output_dir, output_filename)
- result = mammoth.convert_to_html(docx_fileobj, styles=styles, convert_image=convert_image)
+ result = mammoth.convert_to_html(
+ docx_fileobj,
+ style_map=style_map,
+ convert_image=convert_image,
+ )
for message in result.messages:
sys.stderr.write(message.message)
sys.stderr.write("\n")
@@ -90,7 +94,7 @@ def _parse_args():
output_group.add_argument("output", nargs="?")
output_group.add_argument("--output-dir", nargs="?")
- parser.add_argument("--styles", required=False)
+ parser.add_argument("--style-map", required=False)
return parser.parse_args()