# "Literate" leaves behind extraneous #

**URL:** <https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777>\
**Category:** General Usage\
**Created:** [August 12, 2020, 3:38am UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777 "2020-08-12T03:38:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 12, 2020, 3:38am UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/1 "2020-08-12T03:38:24Z")

</div>

I use “cells” in a Julia script. VS code can execute these cells with a single keystroke.

The problem is that when I generate the markdown from the script with Literate, the cell markers (##) are interpreted as markdown and their remnants are left behind.

![image](https://global.discourse-cdn.com/julialang/original/3X/e/a/eae093d19e5559b98ecd1ff384e6f92c3a9098fb.png)  
As you can see it is interpreted as a comment within code.

Has anyone figured out what to do with these cell markers in markdown?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 12, 2020, 8:27am UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/2 "2020-08-12T08:27:52Z")

</div>

Is this something specific to VS Code, or does it happen in other environments?

Do you have an MWE?

Depending on this, I would consider opening an issue for the VS Code plugin, or Literate.jl.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 12, 2020, 9:07am UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/3 "2020-08-12T09:07:20Z")

</div>

If I understand correctly this should be an issue with Literate - VSCode only comes into play as it defines the syntax for cell delimiters (`##`) which isn’t understood by Literate.

Tangentially related - how do you get cells in VSCode? Just putting in `## New cell` doesn’t seem to do anything for me, and I can’t see anything in the settings on this?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 12, 2020, 9:18am UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/4 "2020-08-12T09:18:13Z")

</div>

Next release of the VSCode extension will also [support `# %%` as cell delimiters](https://github.com/julia-vscode/julia-vscode/pull/1575), so that should be a workaround, right?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 12, 2020, 3:58pm UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/5 "2020-08-12T15:58:20Z")

</div>

I’m afraid that will not solve the problem. Literate will process it as

![image](https://global.discourse-cdn.com/julialang/original/3X/4/c/4c47a7cc102de5c8f0c7f6d55818ac6b56247a98.png)

So, as you can see, this text is again interpreted as Julia code.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 12, 2020, 4:21pm UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/6 "2020-08-12T16:21:37Z")

</div>

Here is a sample:

```julia
##
# ## Cross-section

# Cross-sectional properties are incorporated in the cross-section property.
# There are several rectangular cross-sections in the model: the fuselage, the
# wing, the tail. There are also three massless connectors: connections between
# the fuselage and the wing, between the wing structure and the viscoelastic
# damping layer, and between the fuselage and the tail.

using FinEtoolsFlexBeams.CrossSectionModule: CrossSectionRectangle
# Body of the frame (fuselage).
cs_body = CrossSectionRectangle(s -> 1.5*L, s -> L/2, s -> [1.0, 0.0, 1.0]; label = 1)

```

This cell can be evaluated with Shift+Enter.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 12, 2020, 4:22pm UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/7 "2020-08-12T16:22:30Z")

</div>

No, this is specific to VS code. Other editors, as far as I know, do not handle “cell evaluation”.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [August 12, 2020, 4:47pm UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/8 "2020-08-12T16:47:40Z")

</div>

Shoot! I figured out that placing the “cell” marker as `#!md ##` would filter out that extra `#`.  
Unfortunately, this is no longer recognized as a cell marker by VS code.

---

<div class="post-metadata">

**Author:** ![st1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/st1/32/26929_2.png) [@st1](https://discourse.julialang.org/u/st1)\
**Post date:** [July 8, 2021, 9:49am UTC](https://discourse.julialang.org/t/literate-leaves-behind-extraneous/44777/9 "2021-07-08T09:49:12Z")

</div>

Literate.jl accepts a `preprocess` function, you can remove the `##` lines with the following:

```julia
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 combined with `m`, see [perlre - Perl regular expressions - Perldoc Browser](https://perldoc.perl.org/perlre#Modifiers)) and removes it.

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