Comments (2)
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:
- 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 - L118: Removing the date formatting to just
date
- 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.
Thanks a lot guys, and thanks for your effort @ethanbond 👍
from github-markdown-toc.
Related Issues (20)
- [ BUG ] No --insert option in homebrew's gh-md-toc HOT 3
- [Feature] NPM Package HOT 1
- [ BUG ] ":" symbol generates unnecessary hyphen
- [Feature] Auto insert support recursive folders, and auto skip files without `<!--ts-->` HOT 2
- [Feature] Add --hide-footer when using --insert
- [ BUG ] Wrong filename in Github Action (the trailing ".md" should be removed)
- [Feature] Suggestion: put `Created by …` as a HTML comment HOT 1
- [ BUG ] Insert does not work on MacOS 10.15.7 zsh HOT 4
- [Question] release HOT 1
- [SKIP headers before ts -- te] HOT 2
- [Feature] Documentation enhancement for Github Actions
- [ BUG ] --indent argument makes the script crashed
- [ BUG ] ... HOT 2
- 1. Add Content in a block. Example -
- [ BUG ] ... Unable to generate TOC
- [ BUG ] ...
- [ BUG ] No Table of Contents output HOT 2
- [Question] Is this still working? HOT 7
- [Feature]
- [Question] how to bring up command probiotics iphoo ok fr se
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from github-markdown-toc.