-
Notifications
You must be signed in to change notification settings - Fork 20
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
Newlines get ignored #125
Comments
Seems like a bug |
As we also struggle with this, some thoughts here: Architectural ChallengeWith only having scratched the very surface of BBob, I see an architectural challenge in mapping, as there does not seem to be a "non-BBCode-tag" to element mapping approach. We would have some plain text content here, that in some contexts (thus, non-code-/non-preformatted-contexts) should get newlines transformed to an element.
|
To address JiLiZART/BBob#125 diving somewhat deeper into the BBob API. Assumption is, that the best place to respect paragraphs is the `process` method, as we require dedicated handling of text nodes and must not take them as is. The current state is more of "inlining the HTML5-Preset", so that we may start with experiments.
To address JiLiZART/BBob#125 adding some utility method to handle contents of a tag and respect paragraphs within.
Thought I'd add my team's work to the discussion in case someone wants to go down the We created a plugin that will walk the tree and insert https://github.com/RpNation/bbcode/blob/main/bbcode-src/plugins/lineBreak.js /**
* Plugin that converts line breaks to `<br/>` tags.
* To use, put as function similar to the presets.
*
* If a node is marked with `noLineBreakConversion`, then it'll skip the parsing the children
*
* @example
* ```ts
* const output = bbob([preset(), lineBreakPlugin()]).process(input, {render}).html
* ```
*/
import { isEOL } from "@bbob/plugin-helper";
/**
* Checks if input is an object
* @param value input
* @returns if value is an object
*/
const isObj = (value) => typeof value === "object";
/**
* Walks the tree of nodes. Will add `br` tag to all `\n` in format that can be used in any renderer.
* Preserves \n so that markdown-it doesn't try to treat everything like a block
*
* If a node has the property noLineBreakConversion is encountered, will skip parsing children.
* @param t tree of nodes to be processed
* @returns modified tree
*/
const walk = (t) => {
const tree = t;
if (Array.isArray(tree)) {
for (let idx = 0; idx < tree.length; idx++) {
const child = walk(tree[idx]);
if (Array.isArray(child)) {
tree.splice(idx, 1, ...child);
idx += child.length - 1;
} else {
tree[idx] = child;
}
}
} else if (tree && isObj(tree) && tree.content) {
if (tree.disableLineBreakConversion) {
// stop walk. children won't be parsed to have <br>
return tree.tag ? tree : tree.content;
}
walk(tree.content);
}
if (isEOL(tree)) {
return [{ tag: "br", content: null }, "\n"];
}
return tree;
};
/**
* Converts `\n` to `<br/>` self closing tag. Supply this as the last plugin in the preset lists
*
* @example converts all line breaks to br
* ```ts
* const output = bbob([preset(), lineBreakPlugin()]).process(input, {render}).html
* ```
* @example will not convert line breaks inside [nobr]
* ```ts
* const nobr = (node: TagNode) => {return { disableLineBreakConversion: true, content: node.content }}; \\ tag in preset
* ...
* const output = bbob([preset(), lineBreakPlugin()]).process(input, {render}).html
* ```
* @returns plugin to be used in BBob process
*/
export const lineBreakPlugin = () => {
return (tree) => walk(tree);
}; We made the deliberate choice to preserve We just call the plugin after the preset. The intention is to run this as the final step before rendering. bbob([preset(), lineBreakPlugin()]).process(code, {
render,
...options,
}); So as a bit of background, we're using BBob as our future bbcode engine for migration from Xenforo, which also does the I think this is enough for fulfilling the |
@Alteras1, thanks for your workaround for We skipped though, as we need the result to be parsed as CKEditor 5 data view, which again works best having paragraphs instead. And this again requires more "context awareness" best represented in a preset. Our solution is a custom preset, mostly a copy of the HTML5 Preset (thus, we reuse the Our solution mainly consists of these adaptations:
Find more details in current snapshots:
Or as part of this pull request, introducing BBCode support as CKEditor 5 Plugin: CoreMedia/ckeditor-plugins#158 (possibly including more refactorings, as the PR is still in progress). Intermediate Conclusion: Whatever the solution for this issue will be - we obviously need customization options depending on who is the consumer of the generated HTML. |
Any newline character seems to be ignored, leaving my content rendered all on a single line. The conversion to react / html components is working but due to the ignoring of new lines it doesn't display correctly.
Is there a setting for this?
The text was updated successfully, but these errors were encountered: