executablebooks / jupyter-book

Create beautiful, publication-quality books and documents from computational content.
http://jupyterbook.org
BSD 3-Clause "New" or "Revised" License
3.77k stars 652 forks source link

rendering strikethrough #726

Open parmentelat opened 4 years ago

parmentelat commented 4 years ago

Describe the bug markdown strikethrough is not rendered under my jupyter book environment, while it shows nicely in classic notebook

my notebook renders a markdown table like this

image

resulting html book renders this instead

image

To Reproduce

any text marked as strikethrough using markdown ~~ - not necessarily in a table btw - will exhibit the issue

Expected behavior

Would expect the default behaviour of jupyter book to be in line with the default behaviour of jupyter (classic in my case); I am not aware of any customization I would have done on the classic end - although my memory may be failing me here)

if this is a configuration option, it'd be nice if it showed up when searching for strike in the readthedocs documentation

Environment (please complete the following information):

$ python --version
Python 3.7.4
$ jupyter book --version
Jupyter Book: 0.7.0
MyST-NB: 0.8.3
Sphinx Book Theme: 0.0.27
MyST-Parser: 0.9.0
Jupyter-Cache: 0.2.2

Additional context Add any other context about the problem here.

choldgraf commented 4 years ago

Thanks for bringing this up! Strikethroughs are not actually supported in CommonMark, and they work in Jupyter Notebooks because the markdown library it uses has an extension for it. That said, I think it's worth discussing if this should be added to MyST as it is quite common. I'll mark this issue as a feature request, not a bug.

drscotthawley commented 4 years ago

Hey @choldgraf I've been assembling a set of 'manual' pre-processing directives to make my FastPages blog look more like I expect from Typora, Jupyter, etc. e.g. this one for bare URLs: https://github.com/fastai/fastpages/issues/326, and I'm about to add one for == style highlighting. This strikethrough thing seems to be functionally the same thing.

In fact I'm about to (try to) transition from a 'private Fastpages blog' format to Jupyter book format, so I'll be happy to share whatever script I come up with.

drscotthawley commented 4 years ago

Something like this? Currently I just run this 'manually', but it could be incorporated somehow into the build.

#! /usr/bin/env sh
# 
# Tries to make non-standard Markdown usages render more 'universally'
# 
# Sample usage:
# $  ./pre_md_script.sh _posts/*.md
#
# Currently this overwites files in place. 
# Probably would be better to modify a *copy* of the .md file during HTML conversion...?

for f in $*
do
  echo "Processing $f file..."

  # Put angle-brackets around bare URLs
  perl -i.orig  -pe 's/(?!>)^(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*))(?!>)$/<$1>/g' $f

  # Convert MD highlighting to HTML equivalent
  perl -i.orig -pe 's/==(.*?)==/<mark>\1<\/mark>/g' $f

  # Convert MD strikethrough to HTML equivalent
  perl -i.orig -pe 's/~~(.*?)~~/<strike>\1<\/strike>/g' $f

done

WARNING: So far I've only tested this on bare Markdown files, not Jupyter notebooks.

chrisjsewell commented 4 years ago

Actually strikethrough is already implemented: https://github.com/executablebooks/markdown-it-py/blob/master/markdown_it/rules_inline/strikethrough.py, its just not on by default 😉 Exposing configuration of markdown-it extensions is on the TODO list

chrisjsewell commented 4 years ago

Oh yeh and there's no default sphinx representation of strike-through text (which is why it hasn't been added yet), so it needs a small extension on that end; to add the HTML tags + ideally a representation in latex

firasm commented 2 years ago

In case someone else needs this feature and found this open issue (like me), as a workaround, instead of surrounding with ~~ you can instead do:

<strike>text to be struck out</strike>

which will render in JupyterBook as:

text to be struck out.

HTH.

chrisjsewell commented 2 years ago

Note this will be partially supported (HTML only) in a future jupyter-book release, once myst-parser v0.17 has been released and "bubbled up": https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#strikethrough

parmentelat commented 1 year ago

Hiya lads

I just gave this another go, but am still out of luck

I did add the strikethrough extension to myst_enable_extensions but then I am getting

ERROR: myst configuration invalid: myst_enable_extensions not recognised: {'strikethrough'}

upon further digging it appears that I do not have myst-parser v0.17 and it looks like myst-parser is pinned to 0.15.2 at least in my setup (I cant' seem to upgrade that particular piece of the stack, at least when I do I am getting other errors) see below for a glimpse on these

is it just me who have a rotten setup ? if not, is there any plan to remove this limitation in the future ?

thanks in advance for your insights


     from myst_parser import setup_sphinx as setup_myst_parser
ImportError: cannot import name 'setup_sphinx' from 'myst_parser' (/.../miniconda3/envs/ue12-p22-python/lib/python3.10/site-packages/myst_parser/__init__.py)
choldgraf commented 1 year ago

@parmentelat nope, you are correct! We are in the process of updating the various parts of the MyST stack to their latest versions in Jupyter Book - check that effort here: