\l[a]
\l[b]
\l[c
\l[d]
\l[e]
]
\l[f]
\l[a]
\l[b]
\l[c
\l[d]
\l[e]
]
\l[f]
\C[[
some code snippet
that was indented on source!
]]
Markdown essentially does it only for insane lists.
Maybe we should drop this and keep it that way for insane lists only.
This is hard to implement on parsing, likely has to go into tokenizer, which makes things harder.
Tokenizer cannot distinguish element types easily. So if we do only for certain types, then it would be hard to have a version that works on sane element type as well.
One thing we could do is to compress multiple whitespaces on parse or step to a single whitespace when it does not alter the output! We kind of already do something similar with remove_whitespace_children
.
\h[4][Argument automatic indentation removal]
Inside of a non-literal block, the very first non-whitespace character determines the indentation level of the content.
This allows seamlessly indenting complex nested content to make it more readable.
For example, a list with complex content could be written without indentation as:
``
\l[a]
\l[
b
\C[[
And now some code
]]
And a paragraph.
]
\l[c]
``
but it would be more readable as the equivalent:
``
\l[a]
\l[
b
\c[[
And now some code
]]
And a paragraph.
]
\l[c]
``
If a something tries to reduce the current indentation level, then that leads to an error:
``
\l[a]
\l[
b
I'm bad because I have negative indentation.
Back to good.
]
\l[c]
``
// Indentation auto-removal.
// https://github.com/************/cirodown/issues/25
assert_convert_ast('indentation auto-removal simple',
`\\C[
aa
bb
]
`,
[
a('C', [t('aa\nbb\n')]),
]
);
assert_convert_ast('indentation auto-removal literal',
`\\C[[
aa
bb
]]
`,
[
a('C', [t('aa\nbb\n')]),
]
);
assert_convert_ast('indentation auto-removal named',
`\c[aa]{id=
bb
cc
}
`,
[
a('C', [t('aa\nbb\n')], {id: 'bb\ncc\n'}),
]
);
assert_convert_ast('indentation auto-removal with paragraph',
`\\l[
aa
bb
]
`,
[
a('ul', [
a('l', [
a('p', [t('aa')]),
a('p', [t('bb\n')]),
]),
]),
]
);
assert_convert_ast('indentation auto-removal nested',
`\\l[
aa
\\l[
bb
]
]
`,
[
a('ul', [
a('l', [
t('aa\n'),
a('ul', [
a('l', [
t('bb\n'),
]),
]),
]),
]),
]
);
assert_error('indentation auto-removal negative',
`\\C[
aa
bb
]
`, 3, 1);