seth-brown / formd Goto Github PK
View Code? Open in Web Editor NEWA Markdown formatting tool
License: MIT License
A Markdown formatting tool
License: MIT License
Very similar to what formd does, there is the issue of two styles of footnotes: inline and reference footnotes.
I think it would be a great addition for formd to do switch between those footnote styles as well. Would make Academic Writing in Markdown much easier.
I format my markdown with tw=78 so sometimes I might get a link that has a line break in it e.g.
lorem ... [this is my
link] (url)
Currently formd doesn't recognise this as a link
Colons that follow links may result in lines removed from the expected output.
Input file:
* [link text](http://link.com)
* [link 1 text](http://link1.com):
Command formd -r
Output:
* [link text][1]
[1]: http://link.com
[2]: http://link1.com
Problem: the line containing link 1 text is missing from the output.
Input file:
`[x][y]`
Command: formd -r
Output:
`[x][1]`
[1]: y
Expected output:
`[x][y]`
Input file:
[x][y]
(note the 4-space indent)
Command: formd -r
Output:
[x][1]
[1]: y
Expected output:
[x][y]
Similarly for code indented by 1 tab, instead of 4 spaces—the alternative syntax.
Maybe it would be better to internally use a dedicated markdown parser like mdast rather than reimplement something that can catch all these fiddly details?
Using formd to flip link style on a document containing MultiMarkdown footnotes will mangle the footnotes. Specifically, while the inline footnote numbering is retained (in most cases – consecutive footnote numbers retain only the first), the body of the fist footnote will be concatenated to the text if there are several footnotes, while the following get deleted (as does a lone footnote body).
As reproducing this will be easier than trying to describe it, I have prepared two test documents, formd inline link test document and formd reference link test document – I suggest downloading those and trying out what happens on flipping to get a clearer grip on the issue.
The regular expression for finding links seems to be a bit loose.
self.match_links = re.compile(r"""(\[[^^]*?\])\s? # text
(\[.*?\]|\(.*?\r?\n?.*?\)\)?) # ref/url
""", re.MULTILINE | re.X)
For example, markdown text like this:
This morning, a friend noted a discrepancy between two recent headlines at The Mac Observer:
+ March 5: "[Apple CFO Peter Oppenheimer to Retire, Luca Maestri to Take Over][tmo1]"
+ May 7: "[PR Queen Katie Cotton Leaving Apple][tmo2]"
[tmo1]\: http://www.macobserver.com/tmo/article/apple-cfo-peter-oppenheimer-to-retire-luca-maestri-to-take-over
[tmo2]\: http://www.macobserver.com/tmo/article/pr-queen-katie-cotton-leaving-apple
[I tweeted the two headlines and corresponding URLs][t], with a single word of commentary: "Hmm". I said no more partly because I was near the 140-character limit, and partly to see what the reaction would be. Some got it, but many repliers missed my point, mistakenly thinking it was related to an exodus of executives from the company.<sup id="fnr1-2014-05-08">[1]</sup>
My point was to draw attention to the disparate job descriptions: "Apple CFO" vs. "PR Queen".
[Julia Richert pointed to][j] a similar discrepancy -- two Philip Elmer-DeWitt headlines on his weblog at CNN/Fortune/Money
will match items thus:
[Apple CFO Peter Oppenheimer to Retire, Luca Maestri to Take Over][tmo1]
[PR Queen Katie Cotton Leaving Apple][tmo2]
[tmo1]: http://www.macobserver.com/tmo/article/apple-cfo-peter-oppenheimer-to-retire-luca-maestri-to-take-over [tmo2]: http://www.macobserver.com/tmo/article/pr-queen-katie-cotton-leaving-apple \n [I tweeted the two headlines and corresponding URLs][t]
[1]</sup> \n My point was to draw attention to the disparate job descriptions: "Apple CFO" vs. "PR Queen". \n [Julia Richert pointed to][j]
To tighten up the regex, I suggest the following change, which appropriately catches all markdown links, but only markdown links:
self.match_links = re.compile(r"""(\[[^^\[\]:]*?\])\s?? # text
(\[[^\[\]:]*?\]| # ref
\(.*?\r?\n?.*?\)\)?) # url
""", re.MULTILINE | re.X)
Clearly, the only real change is to add to the characters that cannot be within the linked text or in the reference id.
After my comment to Issue #4 I updated to the latest version of formd
, commit be5d17f237dddd1970c6d94eaf175fa7c5378167
and this fixed all my footnote related problems. Thank you again for your quick
fix.
Now I noticed a problem with the link conversion in a rather lenghty post of
mine. Whenever a link is at the start of a line, the following body text gets
truncated. Putting any character in front of the link returns the full
functionality of formd
.
Let me demonstrate with this example file formd_test_file.markdown
:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
[Link to google][1]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
[Link to formd][2]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
[1]: http://google.com
[2]: http://drbunsen.github.com/formd/
Output of cat formd_test_file.markdown | formd -r
:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
[1]: [1]
[2]: http://drbunsen.github.com/formd/
Output of cat formd_test_file.markdown | formd -i
:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
All text after the first link gets truncated. In case of formd -r
the
reference at the bottom of the file gets turned into [1]: [1]
. This is, how
I first noticed the problem, because I write my Markdown links inline style and
convert them occasionally to the reference style.
Putting a space before the first link, pushes the problem down to the next link
in the file and is still killing the first link:
cat formd_test_file.markdown | formd -r
:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
[Link to google][1]
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum
dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no
sea takimata sanctus est Lorem ipsum dolor sit amet.
[1]: [1]
[2]: http://drbunsen.github.com/formd/
In the above output the second link and the complete third paragraph are
missing. The reference of the second link is still there, though...
Maybe this is somehow related to Issue #6?
I checked it against the formd
version from the former commit
4b8ab19b50025fa1e20f5f20919841a1d56dc250
and this worked fine. But misses, of
course, the footnote support...
I diffed the two versions and saw, that the differences are only related to the
self_match_links
and self_match_refs
part of formd
. Yeah, makes sense.
However, it seems that my Python-Fu is not strong enough to come up with
a regex, which makes footnotes and links starting at the beginning of a line
working.
Would you be so kind, to have another look at this fine piece of software? Thank you very much for your time and efforts.
Dennis
OrderedDict is new in 2.7.
There's an MIT licensed drop-in replacement for 2.4+ available at http://code.activestate.com/recipes/576693-ordered-dictionary-for-py24/ and on PyPi.
I'd fork/pull request and throw that in, but that either adds a dependency or quadruples the size of formd
, so I thought I'd raise it here first.
Very nice tool. I'd like to set up a package for Sublime Text but it would be much easier having formd
as a reusable module than a command line executable :)
When you run formd on a link that has parentheses around it, the new formatting includes the inside parentheses.
Example:
([link](link.me)) becomes ([link][1] and [1]: link.me)
If you use reference-style links and add them just below the paragraph with the link, rather than putting them all at the bottom of the document, Formd
loses the body text between the reference links. Here's an example to demonstrate:
# Header
Here is my first paragraph with [a link][1].
[1]: http://link-one.com
Here is my second paragraph with [another link][2].
[2]: http://link-two.com
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.