GithubHelp home page GithubHelp logo

Comments (2)

ethanbond avatar ethanbond commented on June 4, 2024

Hi @col-panic, I'm not qualified to be making a PR for this (you don't want me messing with things that delete files...) but in case you're blocked, here are some changes that I made that solve this.

From line 109:

    else
        local toc=`gh_toc_md2html "$gh_src" | gh_toc_grab "$gh_src_copy"`
        echo "$toc"
        if [ "$need_replace" = "yes" ]; then
            local ts="<\!--ts-->"
            local te="<\!--te-->"
            local dt=`date +'%F_%H%M%S'`
            local ext=".orig.${dt}"
            local toc_path="${gh_src}.toc.${dt}"
            local toc_footer="<!-- Added by: `whoami`, at: `date` -->"
            # http://fahdshariff.blogspot.ru/2012/12/sed-mutli-line-replacement-between-two.html
            # clear old TOC
            local comm="/${ts}/,/${te}/{//!d;}"
            sed -i${ext} "$comm" "$gh_src"
            # create toc file
            echo "${toc}" > "${toc_path}"
            echo -e "\n${toc_footer}\n" >> "$toc_path"
            # insert toc file
            sed -i "" "/${ts}/r ${toc_path}" "$gh_src"
            echo
            echo "!! TOC was added into: '$gh_src'"
            # echo "!! Origin version of the file: '${gh_src}${ext}'"
            # echo "!! TOC added into a separate file: '${toc_path}'"
            rm "$gh_src$ext"
            rm "$toc_path"
            echo
        fi

Note that I'm removing the generated .orig and .toc files. You may not want to do that.

The relevant changes are:

  1. L121-ish: Adding a semicolon after the {//d} to {//d;} per https://stackoverflow.com/questions/6287755/using-sed-to-delete-all-lines-between-two-matching-patterns
  2. L118: Removing the date formatting to just date
  3. L127-ish: Adding an empty param "" per https://stackoverflow.com/questions/16745988/sed-command-with-i-option-in-place-editing-works-fine-on-ubuntu-but-not-mac

Hope this helps!

from github-markdown-toc.

col-panic avatar col-panic commented on June 4, 2024

Thanks a lot guys, and thanks for your effort @ethanbond 👍

from github-markdown-toc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.