(options)
| 37 | } |
| 38 | |
| 39 | async function updateSectionWith(options) { |
| 40 | const { |
| 41 | from, |
| 42 | relativeHeadingLevel, |
| 43 | name, |
| 44 | path, |
| 45 | prefix, |
| 46 | showHeading, |
| 47 | suffix, |
| 48 | tabLevel, |
| 49 | to, |
| 50 | withKey, |
| 51 | withToc, |
| 52 | } = { ...defaultOptions, ...options }; |
| 53 | let md = await readContentFromPath(path); |
| 54 | let oldFences = getFenceForSection(from, name); |
| 55 | let fenceOptions = { |
| 56 | name, |
| 57 | content: md, |
| 58 | tabLevel, |
| 59 | relativeHeadingLevel, |
| 60 | showHeading, |
| 61 | withKey, |
| 62 | prefix, |
| 63 | suffix, |
| 64 | }; |
| 65 | let newFences = generateContentForSection({ |
| 66 | ...fenceOptions, |
| 67 | withToc: false, |
| 68 | }); |
| 69 | let oldTocFences = getFenceForSection(from, name, true); |
| 70 | let newTocFences = generateContentForSection({ |
| 71 | ...fenceOptions, |
| 72 | withToc: true, |
| 73 | }); |
| 74 | let updatedContents = to.replace(oldFences.regex, newFences); |
| 75 | updatedContents = updatedContents.replace(oldTocFences.regex, newTocFences); |
| 76 | if (withToc) |
| 77 | console.log( |
| 78 | `✅ 🗜️ Rewrote Table of Contents for '${md.frontmatter.title}'` |
| 79 | ); |
| 80 | console.log(`✅ 📝 Rewrote Section for '${md.frontmatter.title}'`); |
| 81 | return updatedContents; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Adjusts the headings in the given `markdown` to be in a given heading context. |
no test coverage detected