Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add an option to allow indention #260

Open
Farnsi opened this issue Apr 27, 2023 · 5 comments
Open

Feature: Add an option to allow indention #260

Farnsi opened this issue Apr 27, 2023 · 5 comments

Comments

@Farnsi
Copy link

Farnsi commented Apr 27, 2023

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.

@cookpete
Copy link
Owner

Does custom templates not solve this?

@Farnsi
Copy link
Author

Farnsi commented May 15, 2023

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

@cookpete
Copy link
Owner

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?

@Farnsi
Copy link
Author

Farnsi commented May 15, 2023

Yes for compatibility it would be the best solution.

@Sewer56
Copy link

Sewer56 commented Jul 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants