joeyespo / grip

Preview GitHub README.md files locally before committing them.
MIT License
6.42k stars 421 forks source link

rst support #160

Open kootenpv opened 8 years ago

kootenpv commented 8 years ago

Is there a way to test locally how .rst (restructured text) would look like on github?

joeyespo commented 8 years ago

I still don't have a strong intention to include this since GitHub's Readme API doesn't support it. But since this keeps coming up (#92, #37, #113), and with the newfound focus on the offline renderer (#35), it might be worth taking a serious look.

Keeping this open for discussion and implementation advice.

pdurbin commented 8 years ago

https://github.com/github/markup is described as "The code we use to render README.your_favorite_markup" so I would guess that the list of supported formats there (which includes .rst) matters more to users of grip than the list of supported formats for the API that grip calls ( https://developer.github.com/v3/markdown/ ). To end users of grip, the calling of that API probably feels like an implementation detail of how grip works internally.

https://github.com/github/markup/blob/master/lib/github/commands/rest2html appears to be the Python script GitHub uses to turn .rst files into HTML. I kind of feel like that whole library could/should be wrapped by grip or something similar. That way you'd get all the formats.

mitar commented 8 years ago

+1

ulope commented 7 years ago

As a workaround you can use readme_renderer which additionally has th eoption to ensure compatibility with PyPI

bjodah commented 7 years ago

One work around is to use rst2html.py, optionally with custom css, e.g. https://github.com/matthiaseisen/docutils-css

polyzen commented 7 years ago

https://github.com/sindresorhus/github-markdown-css

joeyespo commented 7 years ago

@polyzen Wow, awesome resource. Thanks for sharing here!

reece commented 6 years ago

Also consider restview. https://mg.pov.lt/restview/ No github style, unfortunately.

kootenpv commented 6 years ago

Perhaps @joeyespo could say: "yes, I would approve of a rst2html pull request", then I'm sure someone will want to pick this up :)?

poppyschmo commented 6 years ago

Also consider restview. https://mg.pov.lt/restview/ No github style, unfortunately.

@reece, while it's hit and miss, I've found the Warehouse/PyPI stylesheets at times produce a closer approximation of the GitHub look than the genuine article. Guessing the selectors are less discriminating. The source is all sass/scss, but the processed goods can be gotten easily enough.

>$ wget -q -nd -e robots=off -p -A "warehouse.*.css" https://pypi.org && mv ware*css warehouse.css
>$ restview --css warehouse.css,restview.css README.rst

Doesn't fix the whole over-sized heading thing, though. Injecting something like this via browser plugin, or whatever, seems to help:

Array.from(document.getElementsByTagName('h1')).forEach(el => el.outerHTML = el.outerHTML.replace(/<([/])?h1/g, "<$1h2"));

Edit: Actually, after glancing at @polyzen's GH source (instead of just rejecting it outright when it didn't work OOTB), it does seem the better choice, given a little finagling:

>$ sed -i "s/\.markdown-body/body/g" github-markdown.css

BTW, it's not worth messing with the .pl-* code-highlighting styles, IMO. For example, GitHub's .pl-k ("k" for keyword, apparently) corresponds to restview's .nb (Pygment's Name.Builtin). But all the Pygments stuff gets in-lined after anything passed as --css <my_styles.css>. Also, sometimes simply leaving out ,restview.css as a fallback yields nicer results.

// demote subheadings
Array.from(document.querySelectorAll("h1,h2,h3")).slice(1)
    .forEach(el => el.outerHTML = el.outerHTML
    .replace(/(<[/]?h)(\d)/g, (_, m, n) => m + (Number(n) + 1)));

P.S. @joeyespo, sorry for the non-grip chatter; I do use it, and it's amazing. C.C. @mgedmin

kootenpv commented 6 years ago

@poppyschmo This is really nice... for a hack.

chey commented 2 years ago

Just a thought here. One way to handle this could be to use something like pandoc to convert rst(s) to markdown on the fly, then use the markdown as you normally would.

zellyn commented 9 months ago

I ended up here because I tried rendering an org-mode file with grip just to see if it worked (it didn't!)