def test_quotify_2(self): """Tests quotify() #2.""" ## test.md: This is 'test 2'. ## # Command: pandoc test.md -f markdown+smart -t json src = eval(r'''{"meta":{},"blocks":[{"t":"Para","c":[{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Quoted","c":[{"t":"SingleQuote"},[{"t":"Str","c":"test"},{"t":"Space"},{"t":"Str","c":"2"}]]},{"t":"Str","c":"."}]}],"pandoc-api-version":[1,17,5,1]}''') # Check src against current pandoc md = subprocess.Popen(('echo', "This is 'test 2'."), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -f markdown+smart -t json'.split(), stdin=md.stdout).strip()) self.assertEqual(src, output) # Command: pandoc -f markdown-smart test.md -t json expected = eval(r'''{"meta":{},"blocks":[{"t":"Para","c":[{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"'test"},{"t":"Space"},{"t":"Str","c":"2'."}]}],"pandoc-api-version":[1,17,5,1]}''') # Check expected against current pandoc md = subprocess.Popen(('echo', "This is 'test 2'."), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -f markdown-smart -t json'.split(), stdin=md.stdout).strip()) self.assertEqual(expected, output) # Make the comparison self.assertEqual(quotify(src['blocks']), expected['blocks'])
def test_quotify_1(self): """Tests quotify() #1.""" ## test.md: "test" ## # Command: pandoc test.md -f markdown+smart -t json src = eval(r'''{"meta":{},"blocks":[{"t":"Para","c":[{"t":"Quoted","c":[{"t":"DoubleQuote"},[{"t":"Str","c":"test"}]]}]}],"pandoc-api-version":[%s]}'''%PANDOC_API_VERSION) # Check src against current pandoc md = subprocess.Popen(('echo', '"test"'), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -f markdown+smart -t json'.split(), stdin=md.stdout).strip()) self.assertEqual(src, output) # Command: pandoc -f markdown-smart test.md -t json expected = eval(r'''{"meta":{},"blocks":[{"t":"Para","c":[{"t":"Str","c":"\"test\""}]}],"pandoc-api-version":[%s]}'''%PANDOC_API_VERSION) # Check expected against current pandoc md = subprocess.Popen(('echo', '"test"'), stdout=subprocess.PIPE) output = eval(subprocess.check_output( 'pandoc -f markdown-smart -t json'.split(), stdin=md.stdout).strip()) self.assertEqual(expected, output) # Make the comparison self.assertEqual(quotify(src['blocks']), expected['blocks'])
def test_quotify_2(self): """Tests quotify() #2.""" ## test.md: This is 'test 2'. ## # Command: pandoc test.md -f markdown+smart -t json src = eval( r'''{"meta":{},"blocks":[{"t":"Para","c":[{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Quoted","c":[{"t":"SingleQuote"},[{"t":"Str","c":"test"},{"t":"Space"},{"t":"Str","c":"2"}]]},{"t":"Str","c":"."}]}],"pandoc-api-version":[1,17,3]}''' ) # Check src against current pandoc md = subprocess.Popen(('echo', "This is 'test 2'."), stdout=subprocess.PIPE) output = eval( subprocess.check_output('pandoc -f markdown+smart -t json'.split(), stdin=md.stdout).strip()) self.assertEqual(src, output) # Command: pandoc -f markdown-smart test.md -t json expected = eval( r'''{"meta":{},"blocks":[{"t":"Para","c":[{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"'test"},{"t":"Space"},{"t":"Str","c":"2'."}]}],"pandoc-api-version":[1,17,3]}''' ) # Check expected against current pandoc md = subprocess.Popen(('echo', "This is 'test 2'."), stdout=subprocess.PIPE) output = eval( subprocess.check_output('pandoc -f markdown-smart -t json'.split(), stdin=md.stdout).strip()) self.assertEqual(expected, output) # Make the comparison self.assertEqual(quotify(src['blocks']), expected['blocks'])
def processor(meta, blocks): """Document processor.""" has_epigraph = False # Flags that an epigraph was found noindent = False # Flags that next para should not be indented # Process the blocks for block in blocks: if block['t'] == 'Div': attrs = PandocAttributes(block['c'][0]) # Process epigraph divs if 'epigraph' in attrs.classes: # Insert tex into div content content = block['c'][1] content[0]['c'].insert(0, PRE) content[-2]['c'].append(MID) for el in content[-1]['c']: content[-2]['c'].append(el) content[-2]['c'].append(POST) del content[-1] # Set flags and continue has_epigraph = True noindent = True continue # Don't indent the first non-empty paragraph after an epigraph if block['t'] == 'Para' and noindent: content = stringify(quotify(copy.deepcopy(block['c']))) if content.strip(): block['c'].insert(0, RawInline('tex', r'\noindent ')) noindent = False if has_epigraph: pandocxnos.add_to_header_includes( meta, 'tex', textwrap.dedent(r''' \usepackage{epigraph} '''), warninglevel)