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

fix post processor not going in proper order of functions #108

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions assets/bundled/bbcode-parser.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

const MD_NEWLINE_INJECT = "<!-- bbcode injected newlines -->\n\n";
const MD_NEWLINE_PRE_INJECT = "\n\n<!-- bbcode pre injected newlines -->";
const MD_NEWLINE_INJECT_COMMENT = "<!-- bbcode injected newlines -->";

const URL_REGEX =
/(http|ftp|https|upload):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])/;
Expand Down Expand Up @@ -2529,8 +2530,10 @@
* @returns post processed string
*/
function removeNewlineInjects(raw) {
const processed = raw.replaceAll(MD_NEWLINE_INJECT, "").replaceAll(MD_NEWLINE_PRE_INJECT, ""); // Remove all instances of the injected newline

const processed = raw
.replaceAll(MD_NEWLINE_INJECT, "")
.replaceAll(MD_NEWLINE_PRE_INJECT, "")
.replaceAll(MD_NEWLINE_INJECT_COMMENT, ""); // Remove all instances of the injected newline
return processed;
}

Expand All @@ -2555,10 +2558,10 @@
* @returns final processed string
*/
function postprocess(raw, data) {
let final = "";
let final = raw;
const postprocessors = [removeNewlineInjects, renderHoistedCodeBlocks];
for (const postprocessor of postprocessors) {
final = postprocessor(raw, data);
final = postprocessor(final, data);
}
return final;
}
Expand Down
2 changes: 2 additions & 0 deletions bbcode-src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const regexIndexOf = (string, regex, startpos) => {

const MD_NEWLINE_INJECT = "<!-- bbcode injected newlines -->\n\n";
const MD_NEWLINE_PRE_INJECT = "\n\n<!-- bbcode pre injected newlines -->";
const MD_NEWLINE_INJECT_COMMENT = "<!-- bbcode injected newlines -->";

const URL_REGEX =
/(http|ftp|https|upload):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])/;
Expand Down Expand Up @@ -89,6 +90,7 @@ export {
preprocessAttr,
regexIndexOf,
MD_NEWLINE_INJECT,
MD_NEWLINE_INJECT_COMMENT,
MD_NEWLINE_PRE_INJECT,
URL_REGEX,
MD_URL_REGEX,
Expand Down
12 changes: 7 additions & 5 deletions bbcode-src/utils/postprocess.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MD_NEWLINE_INJECT, MD_NEWLINE_PRE_INJECT } from "./common";
import { MD_NEWLINE_INJECT, MD_NEWLINE_INJECT_COMMENT, MD_NEWLINE_PRE_INJECT } from "./common";

/**
* Post Processing designed to fix issues with Markdown and BBCode that the parser can't fix.
Expand All @@ -8,8 +8,10 @@ import { MD_NEWLINE_INJECT, MD_NEWLINE_PRE_INJECT } from "./common";
* @returns post processed string
*/
function removeNewlineInjects(raw) {
const processed = raw.replaceAll(MD_NEWLINE_INJECT, "").replaceAll(MD_NEWLINE_PRE_INJECT, ""); // Remove all instances of the injected newline

const processed = raw
.replaceAll(MD_NEWLINE_INJECT, "")
.replaceAll(MD_NEWLINE_PRE_INJECT, "")
.replaceAll(MD_NEWLINE_INJECT_COMMENT, ""); // Remove all instances of the injected newline
return processed;
}

Expand All @@ -34,10 +36,10 @@ function renderHoistedCodeBlocks(raw, data) {
* @returns final processed string
*/
export function postprocess(raw, data) {
let final = "";
let final = raw;
const postprocessors = [removeNewlineInjects, renderHoistedCodeBlocks];
for (const postprocessor of postprocessors) {
final = postprocessor(raw, data);
final = postprocessor(final, data);
}
return final;
}
Loading