This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4164 from gratipay/marky-markdown-package
Modify first h1/p just like npm does
- Loading branch information
Showing
15 changed files
with
264 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
// Extend marky-markdown.js to support the package argument: | ||
// https://www.npmjs.com/package/marky-markdown#npm-packages | ||
|
||
var fs = require('fs') | ||
var path = require('path') | ||
var marky = require('marky-markdown') | ||
|
||
if (process.argv.length < 3) { | ||
console.log('Usage:\n\nour-marky-markdown some.md pkg > some.html') | ||
process.exit() | ||
} | ||
|
||
var filePath = path.resolve(process.cwd(), process.argv[2]) | ||
|
||
fs.readFile(filePath, function (err, data) { | ||
if (err) throw err | ||
var package = process.argv[3] ? JSON.parse(process.argv[3]) : null; | ||
var html = marky(data.toString(), {package: package}) | ||
process.stdout.write(html) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from subprocess import Popen, PIPE | ||
|
||
from markupsafe import Markup | ||
import json | ||
import misaka as m # http://misaka.61924.nl/ | ||
from markupsafe import Markup | ||
|
||
|
||
def render(markdown): | ||
"""Process markdown approximately the same way that GitHub used to. | ||
(Note that as of November, 2016 they are migrating to CommonMark, so we are | ||
starting to drift.) | ||
""" | ||
return Markup(m.html( | ||
markdown, | ||
extensions=m.EXT_AUTOLINK | m.EXT_STRIKETHROUGH | m.EXT_NO_INTRA_EMPHASIS, | ||
render_flags=m.HTML_SKIP_HTML | m.HTML_TOC | m.HTML_SMARTYPANTS | m.HTML_SAFELINK | ||
)) | ||
|
||
|
||
def marky(markdown): | ||
def render_like_npm(markdown, package=None): | ||
"""Process markdown the same way npm does. | ||
Package should be a dict representing the package. If it includes `name` | ||
and `description` then the first h1 and paragraph will have a | ||
'package-{name,description}-redundant' class added to them if they're | ||
similar enough. If it includes `repository.url` then links will be changed | ||
somehow. For details consult the docs and code: | ||
https://github.com/npm/marky-markdown | ||
""" | ||
if type(markdown) is unicode: | ||
markdown = markdown.encode('utf8') | ||
marky = Popen(("marky-markdown", "/dev/stdin"), stdin=PIPE, stdout=PIPE) | ||
return Markup(marky.communicate(markdown)[0]) | ||
cmd = ("bin/our-marky-markdown.js", "/dev/stdin") | ||
if package: | ||
cmd += (json.dumps(package),) | ||
marky = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) | ||
out, err = marky.communicate(markdown) | ||
if marky.wait() > 0: | ||
raise OSError(err) | ||
return out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,6 @@ | |
./vendor/ipaddress-1.0.16.tar.gz | ||
./vendor/cryptography-1.3.2.tar.gz | ||
|
||
./vendor/ijson-2.3.tar.gz | ||
|
||
-e . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE packages ADD COLUMN readme_needs_to_be_processed bool NOT NULL DEFAULT true; |
Oops, something went wrong.