Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could Literate accommodate cells of execution (VS code)? #119

Open
PetrKryslUCSD opened this issue Aug 17, 2020 · 4 comments
Open

Could Literate accommodate cells of execution (VS code)? #119

PetrKryslUCSD opened this issue Aug 17, 2020 · 4 comments

Comments

@PetrKryslUCSD
Copy link

VS code uses 2#'s at the beginning of the line to indicate the start of a cell.
Literate interprets this to leave behind a comment.

Could this be accommodated somehow?
@pfitzseb Also pointed out that the VS code team is thinking about using #%% as the start-of-cell marker.

@st--
Copy link
Contributor

st-- commented Jul 8, 2021

This was discussed on https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777 as well (including some concrete examples).

@st--
Copy link
Contributor

st-- commented Jul 8, 2021

@PetrKryslUCSD you can use the preprocess functionality with a function like the following:

function preprocess(content)
   return replace(content, r"^##$."ms => "")
end

This matches lines that are exactly ##, including the trailing newline (. inside the regexp and s postfix option, see https://perldoc.perl.org/perlre#Modifiers) and removes it.

Pass it to Literate by calling e.g. Literate.markdown(script, outputdir; preprocess=preprocess, kwargs...).

@st--
Copy link
Contributor

st-- commented Jul 8, 2021

It's much cleaner to explicitly use this preprocessing than to build in some hard-coded processing for one specific environment, so should this issue be closed now? (I also pointed out the preprocess solution in the linked discourse thread.)

@fredrikekre
Copy link
Owner

Could be added to the "Tips and Tricks" section in the manual. Would you like to make a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants