cookpete/auto-changelog

Feature: Add an option to allow indention

Farnsi opened this issue · 5 comments

Currently the lines are trimed on output.

I want to show an indented message under the subject

Example:

- Subject
  The Message

Current output is:

- Subject
The Message

In Handlebar templates we can manually control the indention with ~, example {{~subject~}} removes whitespace before and after.

Does custom templates not solve this?

@cookpete I use a custom template, the problem is, that the rendered content will be trimmed on output by auto-changlog, not by handlebars.

Ah good spot! I should add an option to not remove indentation from templates.

Or maybe just never remove indentation for custom templates? Actually, that gets tricky when you have four spaces of indentation...

like this

So maybe a --keep-indentation option?

Yes for compatibility it would be the best solution.

I've found this to be an issue for me too.
I don't work with web tech, but I had a quick peek into the codebase.
This was fairly quick and easy to figure out.

You'd want to do the following:

  1. Add an option to run.js
    • This will propagate into template generator

const getOptions = async argv => {
const commandOptions = new Command()
.option('-o, --output <file>', `output file, default: ${DEFAULT_OPTIONS.output}`)
.option('-c, --config <file>', `config file location, default: ${DEFAULT_OPTIONS.config}`)

  1. Check the option in template.js, skipping the cleanTemplate method if the option is toggled.

const cleanTemplate = template => {
return template
// Remove indentation
.replace(/\n +/g, '\n')
.replace(/^ +/, '')
// Fix multiple blank lines
.replace(/\n\n\n+/g, '\n\n')
.replace(/\n\n$/, '\n')
}
const compileTemplate = async (releases, options) => {
const { template, handlebarsSetup } = options
if (handlebarsSetup) {
const path = /^\//.test(handlebarsSetup) ? handlebarsSetup : join(process.cwd(), handlebarsSetup)
const setup = require(path)
if (typeof setup === 'function') {
setup(Handlebars)
}
}
const compile = Handlebars.compile(await getTemplate(template), COMPILE_OPTIONS)
if (template === 'json') {
return compile({ releases, options })
}
return cleanTemplate(compile({ releases, options }))
}


I believe that should do it. Fairly simple patch.

In my case, I wanted to do nested bullet points

- Main Text
    - Sub Text

Currently it's not possible to do when generating markdown.
Anyway, with that out of the way, it's really down to just deciding what an appropriate name for the parameter would be, --keep-whitespace would be my preferred choice.