diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-03-15 10:46:30 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-03-15 10:46:30 +0000 |
| commit | 496a1f7b16fc8616c12f3ebe469c7bfb18a5c00c (patch) | |
| tree | fad79eab25fdf5ab722d56099f38abe1068c35c2 /mammoth/writers | |
| parent | c99948a464181f4402df5b2b2f175f635b127c0c (diff) | |
Split end arg for to separate str and function args
Diffstat (limited to 'mammoth/writers')
| -rw-r--r-- | mammoth/writers/markdown.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/mammoth/writers/markdown.py b/mammoth/writers/markdown.py index 22bdf1c..c291479 100644 --- a/mammoth/writers/markdown.py +++ b/mammoth/writers/markdown.py @@ -4,16 +4,22 @@ import re class _WriterOutput(object): - def __init__(self, start, end, anchor_position=None): - if not callable(end): - end_output = end - end = lambda: end_output + def __init__(self, start, end=None, generate_end=None, anchor_position=None): + if generate_end is None: + generate_end = _constant(end) self.start = start - self.end = end + self.generate_end = generate_end self.anchor_position = anchor_position +def _constant(value): + def get(): + return value + + return get + + class _MarkdownState(object): def __init__(self): self._list_state_stack = [] @@ -79,7 +85,7 @@ def _list(ordered): end_text = "" indentation = markdown_state.list_state.indentation + 1 - def end(): + def generate_end(): markdown_state.pop_list_state() return end_text @@ -88,7 +94,7 @@ def _list(ordered): indentation=indentation, )) - return _WriterOutput(start, end) + return _WriterOutput(start, generate_end=generate_end) return call @@ -104,14 +110,17 @@ def _list_item(attributes, markdown_state): else: bullet = "-" - def end(): + def generate_end(): if markdown_state.list_item_has_closed: return "" else: markdown_state.list_item_has_closed = True return "\n" - return _WriterOutput(("\t" * list_state.indentation) + bullet + " ", end) + return _WriterOutput( + start=("\t" * list_state.indentation) + bullet + " ", + generate_end=generate_end + ) def _init_writers(): @@ -154,7 +163,7 @@ class MarkdownWriter(object): attributes = {} output = _writers.get(name, _default_writer)(attributes, self._markdown_state) - self._element_stack.append(output.end) + self._element_stack.append(output.generate_end) anchor_before_start = output.anchor_position == "before" if anchor_before_start: |
