Skip to content

Instantly share code, notes, and snippets.

@oboxodo
Last active August 29, 2015 14:23
Show Gist options
  • Save oboxodo/4948ac8e79aa952df8bc to your computer and use it in GitHub Desktop.
Save oboxodo/4948ac8e79aa952df8bc to your computer and use it in GitHub Desktop.
Fixing a malformed AST

I have a bunch of docx files with deep outlines (up to 6 levels deep) in them. The author tried to apply Word's heading styles to each level but for some reason it didn't work as expected.

My goal is to develop a pandoc.org filter which would help me automatically transform from what you can see in original-from-docx.txt to what can be seen in expected-filtered-output.txt. Needless to say this is just a sample of the 268 pages docx file I'm processing.

This is the command I'm running to generate original-from-docx.txt:

pandoc -f docx -t markdown -S -o original-from-docx.txt outline.docx

I'm needing to develop a filter that would:

  1. convert hard line breaks into proper paragraph breaks.
  2. for each new list item, take it's first paragraph, remove any formatting and convert it into a heading according to its nesting level.

But I'm open to other ideas :)

I. # Torts generally
A “tort” generally arises where a person acts, with the requisite
level of culpability, in such a way as to cause legally-cognizable
harm to another person. The law will provide the person who suffered
harm with a civil remedy against the person whose wrongful act
caused the harm. The remedy usually takes the form of money damages.
\[See Black’s Law Dictionary (10th Ed. 2014), tort.\]
A. ## Act
An “act,” for purposes of tort law, may consist of either an
“act of commission” or an “act of omission.” \[*See* Black’s Law
Dictionary (10^th^ Ed. 2014), *act*.\]
1. ### Act of commission
An “act of commission” consists of what most people might
think of as a “positive act” or an “affirmative act.” The
term refers to a movement of the body (especially a
voluntary movement) that produces a discernible effect in
the external world.
*Example:* An adolescent boy sees an adolescent girl
walking by. The boy extends his foot in such a way as to
cause the girl to trip and injure herself. This is an “act
of commission.” The boy’s extension of his foot was a
voluntary bodily act, which was intended to—and did—produce
the external effect of causing the girl to trip.
2. ### Act of omission
An “act of omission” arises when a person fails to do
something, under circumstances where the law imposes an
affirmative duty to do something. \[*See Black’s Law
Dictionary* (10^th^ Ed. 2014), *act of omission, negative
act*.\]
I. <span id="_Toc420059985" class="anchor"></span>**Torts generally**\
A “tort” generally arises where a person acts, with the requisite
level of culpability, in such a way as to cause legally-cognizable
harm to another person. The law will provide the person who suffered
harm with a civil remedy against the person whose wrongful act
caused the harm. The remedy usually takes the form of money damages.
\[See Black’s Law Dictionary (10th Ed. 2014), tort.\]
A. <span id="_Toc420059986" class="anchor"></span>**Act\
**An “act,” for purposes of tort law, may consist of either an
“act of commission” or an “act of omission.” \[*See* Black’s Law
Dictionary (10^th^ Ed. 2014), *act*.\]
1. **Act of commission**\
An “act of commission” consists of what most people might
think of as a “positive act” or an “affirmative act.” The
term refers to a movement of the body (especially a
voluntary movement) that produces a discernible effect in
the external world.
*Example:* An adolescent boy sees an adolescent girl
walking by. The boy extends his foot in such a way as to
cause the girl to trip and injure herself. This is an “act
of commission.” The boy’s extension of his foot was a
voluntary bodily act, which was intended to—and did—produce
the external effect of causing the girl to trip.
2. **Act of omission**\
An “act of omission” arises when a person fails to do
something, under circumstances where the law imposes an
affirmative duty to do something. \[*See Black’s Law
Dictionary* (10^th^ Ed. 2014), *act of omission, negative
act*.\]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment