acornejo / downshow Goto Github PK
View Code? Open in Web Editor NEWA simple library to convert HTML to markdown.
License: MIT License
A simple library to convert HTML to markdown.
License: MIT License
Blockquotes which need to be rendered as >
in markdown are sometimes parsed as >
.
The HTML I used is The actual lecture starts at 6:00 minutes.<div><br><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><span style="font-family: georgia;">Q A session begins at 38:20 minutes.</span></div><div><br></div></blockquote></div>
and it converts to markdown as:
The actual lecture starts at 6:00 minutes.
> Q A session begins at 38:20 minutes.
This is probably because you need to escape the HTML entities, like :
https://code.google.com/p/jslibs/wiki/JavascriptTips#Escape_and_unescape_HTML_entities
Just so you know, I tried to pass > as >
so that it will be escaped as unicode characters. Unfortunately that did not fix the problem.
Since .src
on an IMG node always returns the full path of the src attribute, downshow converts relative paths to absolute paths (in the following line):
var src = node.src ? nltrim(node.src) : '', alt = node.alt ? nltrim(node.alt) : '', caption = node.title ? nltrim(node.title) : '';
So <img src="/img-path.jpg" alt="img">
would become ![img](http://example.com/img-path.jpg)
I assume that's not the intended behaviour, I'll submit a pull request shortly :-)
var html = '<p><b>1</b></p><p><b>2</b></p><p><b>3</b></p>';
var md = downshow(html);
md === '**1**\n**2**\n**3**';
// md should be '**1**\n\n**2**\n\n**3**'
This probably goes for other inline tags as well
Nested lists are not processed properly. I had a first order nested list:
and got the output:
- Enzymes control all metabolic processes in the body. - Factors which affect enzyme activity and therefore optimal metabolic efficiency: - Temperature: as the temperature rises enzymes work faster until their optimum temperature (what they work best at). In human this is 37 0 C (body temp.) - pH: most enzymes optimum is at pH 7, though it varies. - Concentration of enzyme and substrate: the rate of reaction is directly proportionate to the amount of enzyme.
The third list element gets processed as a pre when converting back to HTML.
Also, the input:
- Order one
- Order 1, el 2
- Order 2 el 1
- Order 2 el 2
- Order 3 el 1
- Order 3 El 2
- Order 4 el 1
converts it to:
1. Order one &lt;br&gt; 1. Order 1, el 2 1. Order 2 el 1 1. Order 2 el 2 1. Order 3 el 1 1. Order 3 El 2 1. Order 4 el 1
It does not process second order (or higher) nesting.
BTW, I came across this library when searching for "reverse breadth first" as I was trying to solve the Nested lists issue using a similar approach. It works well for almost all the other markdown spec, but lists (nested) did not cut it. Great work for not using regex which does not do a proper job when encountering unknown tags.
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.