# Get Literate.jl to ignore docstrings

**URL:** <https://discourse.julialang.org/t/get-literate-jl-to-ignore-docstrings/117951>\
**Category:** Performance\
**Tags:** literatejl\
**Created:** [August 8, 2024, 11:51am UTC](https://discourse.julialang.org/t/get-literate-jl-to-ignore-docstrings/117951 "2024-08-08T11:51:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [August 8, 2024, 11:51am UTC](https://discourse.julialang.org/t/get-literate-jl-to-ignore-docstrings/117951/1 "2024-08-08T11:51:50Z")

</div>

How do I get Literate.jl to ignore docstrings?

I have a `*.jl` file defining functions. The functions have docstrings

```julia
"""
 z = foo(x,y)

Great functionality, easy to use.
"""

```

(parsed by Documenter.jl to generate the “reference manual” part of the HTML doc, and read by Julia in `?`-mode).

In addition, I am running the same file through Literate.jl to create an `*.md` file which I feed to Documenter.jl: I want to walk the reader through the source.

The catch is, _I would like Literate.jl to ignore the docstring_, and only process code and comments

```julia
# Now look at this sleek implementation
function foo(x::,y::)
...
end

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 8, 2024, 12:05pm UTC](https://discourse.julialang.org/t/get-literate-jl-to-ignore-docstrings/117951/2 "2024-08-08T12:05:08Z")

</div>

If you don’t have any top level triple strings (other than docstrings) in the file you can use the following as [preprocessor](https://fredrikekre.github.io/Literate.jl/v2/customprocessing/#Custom-pre-and-post-processing) (pass `preprocess = remove_docstrings` to `Literate.markdown`):

```julia
function remove_docstrings(str)
    return replace(str, r"^\"\"\"$.*?^\"\"\"$"ms => "")
end

```

---

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [August 8, 2024, 12:26pm UTC](https://discourse.julialang.org/t/get-literate-jl-to-ignore-docstrings/117951/3 "2024-08-08T12:26:01Z")

</div>

Oh how elegant - I did not study this part of the doc: preprocessors! (and postprocessors… I get the idea).

If I may bother you: `remove_docstrings` leaves my code unchanged (and I never taught myself regexp). Here is my code

```julia
# # DryFriction
# See [`Muscade.DryFriction`](@ref) for reference manual.
#    
# The struct contains the values provided (indirectly) by the user. Note `Fx` and `Ff` which are type parameters.
"""
    DryFriction <: AbstractElement

Add a single-node "dry-friction" resistance to a single X-dof. Because `Muscade`does not allow internal variables,
the element has a second dof which is the friction force.

# Named arguments to the constructor
- `fieldx::Symbol`. The field of the dof to which to apply the dry friction.
- `fieldf::Symbol = :f`. The field of the friction force dof.
- `fric::𝕣`. The absolute value of the friction force.
- `Δx::𝕣=0`. The width over which the friction force builds up.
- `x′scale::𝕣=1.`. A typical order of magnitude of the velocity of the dof to which dry friction is applied.

"""
struct DryFriction{Fx,Ff} <: AbstractElement
    fric :: 𝕣
    x′scale :: 𝕣  
    k⁻¹ :: 𝕣 # ∈ [0,∞[, so k ∈]0,∞]
end
DryFriction(nod::Vector{Node};fieldx::Symbol,fieldf::Symbol=:f,friction::𝕣,Δx::𝕣=0.,x′scale::𝕣=1.) = DryFriction{fieldx,fieldf}(friction,x′scale,Δx/friction)
@espy function Muscade.residual(o::DryFriction, X,U,A, t,SP,dbg) 
    x,x′,f,f′ = ∂0(X)[1],∂1(X)[1], ∂0(X)[2], ∂1(X)[2] # f: nod-on-el convention, the sign is unusual.
    conds = (stick = (x′-o.k⁻¹*f′)/o.x′scale, # Was the system in stick of slip at the previous iteration?
                 slip = abs(f)/o.fric -1 ) # - each condition is matched if expression evals to 0.       
    ☼old = argmin(map(abs,conds)) # Symbol-index of the "most matched" condition
    if old==:stick && abs(f)>o.fric ☼new = :slip # if we were in stick but now |f| exceeds o.fric, we now slip
    elseif old==:slip && f*x′<0 ☼new = :stick # if we were in slip but now the force is is the wrong direction, we now stick
    else ☼new = old # otherwise, no change
    end                  
    return SVector(f,conds[new]), noFB
end
Muscade.doflist( ::Type{DryFriction{Fx,Ff}}) where{Fx,Ff} = (inod =(1 ,1 ), class=(:X,:X), field=(Fx,Ff)) 

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 8, 2024, 12:36pm UTC](https://discourse.julialang.org/t/get-literate-jl-to-ignore-docstrings/117951/4 "2024-08-08T12:36:33Z")

</div>

It works for me. Are you on Windows? Perhaps you need to prepend `(*ANYCRLF)` to the regex then, i.e.

```julia
function remove_docstrings(str)
    return replace(str, r"(*ANYCRLF)^\"\"\"$.*?^\"\"\"$"ms => "")
end

```

---

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [August 8, 2024, 12:41pm UTC](https://discourse.julialang.org/t/get-literate-jl-to-ignore-docstrings/117951/5 "2024-08-08T12:41:03Z")

</div>

Hi Frederik,

That works perfectly! Thank you for your help, and thank you for creating Literate.jl !

🙂

Philippe
