# Strip out YAML blocks

**URL:** <https://discourse.julialang.org/t/strip-out-yaml-blocks/29059>\
**Category:** General Usage\
**Tags:** strings\
**Created:** [September 23, 2019, 6:43am UTC](https://discourse.julialang.org/t/strip-out-yaml-blocks/29059 "2019-09-23T06:43:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [September 23, 2019, 6:43am UTC](https://discourse.julialang.org/t/strip-out-yaml-blocks/29059/1 "2019-09-23T06:43:14Z")

</div>

Is there an easy way to strip yaml blocks from markdown files, or more concretely - anything between and including the first and second occurence of `---` and `---`.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 23, 2019, 6:46am UTC](https://discourse.julialang.org/t/strip-out-yaml-blocks/29059/2 "2019-09-23T06:46:24Z")

</div>

wow, can’t believe I just wrote something (jank 1000) for this last week:  
[https://github.com/Moelf/BigG.jl/blob/9f79a16266da89584018bd324198a2874c3146fb/src/BigG.jl#L79-L85](https://github.com/Moelf/BigG.jl/blob/9f79a16266da89584018bd324198a2874c3146fb/src/BigG.jl#L79-L85)

if you want the block inclusively, just remove `+1` and `-1`

now that I’m posting my inefficient code, I have to make a version where you don’t have to read the whole file:

```julia
function revise(path)    
    t = open(path)       
    lines = []               
    c = 0                
    while c<2       
        r = readline(t)
        (r == "---" && (c+=1))              
        push!(lines, r)                  
    end                           
    return join(lines, "\n")    
end  

```

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [September 23, 2019, 7:04am UTC](https://discourse.julialang.org/t/strip-out-yaml-blocks/29059/3 "2019-09-23T07:04:28Z")

</div>

Thanks. I reworked your example to keep the md and remove the YAML:

```julia
# Remove YAML block
mdlines = readlines(file)
md = join(mdlines[findall(x -> x=="---", mdlines)[2]+1:end], "\n")
write(file, md)

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 23, 2019, 7:08am UTC](https://discourse.julialang.org/t/strip-out-yaml-blocks/29059/4 "2019-09-23T07:08:38Z")

</div>

ah, didn’t realize stripe means get rid off, I thought you want to extract that block of YAML (biased based on my use case of course), in that case `readlines` should be just fine.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [September 23, 2019, 7:10am UTC](https://discourse.julialang.org/t/strip-out-yaml-blocks/29059/5 "2019-09-23T07:10:51Z")

</div>

No worries! It did most of what I needed. I’m trying to use .jmd files from Weave.jl in Documenter.jl, and Documenter doesn’t seem to handle .jmd yet so I’m just deleting the YAML
