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: close unclosed tags in html parser and trim indentation of md content lines #332

Merged

Conversation

razortanmayshah
Copy link
Contributor

@razortanmayshah razortanmayshah commented Mar 28, 2024

Changes Made :

  1. Extend md utitlity to close unclosed tags.
    Reason : In Citadel's markdown to html parser, some tags were left unclosed which generates incorrect html syntax. This generated html is used to build Algolia records.
    Until now, we were not doing HAST parsing while building Algolia records, hence, this error went unnoticed. Now, we are parsing HAST for generating granular search records. Hence need this fix.

  2. Trim indentation of md content before rendering to html
    Reason: if content is not trimmed, then this results in incorrect interpretation of indentation resulting in errors like adding codeblocks whenver indentation > 3 etc. One more benefit of this is that record size is decreased by a great extent. No of heaving records decreased from 12 to 4.

@razortanmayshah razortanmayshah self-assigned this Mar 28, 2024
@razortanmayshah razortanmayshah changed the title fix: close unclosed tags in markdown to html parser fix: close unclosed tags in html parser and trim indentation of md content lines Mar 29, 2024
@@ -82,7 +82,7 @@ module.exports = function (body, config, docPath) {
function (_, indent, openTag, content) {
attrs = getAttrs(openTag, docPath, config);

if (config.org === attrs.org) return `${indent}${content}`;
if (config.org === attrs.org && config.countryCode === attrs.country ) return `${indent}${content}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had added a new attribute org-country earlier, which TWs are using now. Does that also need to be checked here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check this and update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support for this will be added later. For now, this attribute is only used for razorpay-IN org and axis org.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org-country attribute has been used for razorpay-IN and axis-IN. That content will get skipped if we don't check for it.
Logic for this is in docs-website webpack-loaders/remark-plugins/remark-plugin-whitelabel/index.js. Might need to duplicate that code here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, this attribute is only used for razorpay-IN org and axis org.

Why is this not being used for Curlec?

scripts/md.js Show resolved Hide resolved
scripts/md.js Show resolved Hide resolved
scripts/md.js Show resolved Hide resolved
build-search.js Show resolved Hide resolved
plugins.js Show resolved Hide resolved
build-search.js Outdated
const parsedContentWithFrontmatter = {
...parsedContent,
...doc.frontMatter,
body: content,
href: doc.href,
content: parsedContent.content.split('\n').join(''),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why is this required? Is this another thing which was missed earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a comment on this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done to remove the extra spacing and trim down the html dom string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this as a comment in code

Copy link

@PranjalMaithani PranjalMaithani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with 2 comments

@@ -82,7 +82,7 @@ module.exports = function (body, config, docPath) {
function (_, indent, openTag, content) {
attrs = getAttrs(openTag, docPath, config);

if (config.org === attrs.org) return `${indent}${content}`;
if (config.org === attrs.org && config.countryCode === attrs.country ) return `${indent}${content}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org-country attribute has been used for razorpay-IN and axis-IN. That content will get skipped if we don't check for it.
Logic for this is in docs-website webpack-loaders/remark-plugins/remark-plugin-whitelabel/index.js. Might need to duplicate that code here.

@@ -82,7 +82,7 @@ module.exports = function (body, config, docPath) {
function (_, indent, openTag, content) {
attrs = getAttrs(openTag, docPath, config);

if (config.org === attrs.org) return `${indent}${content}`;
if (config.org === attrs.org && config.countryCode === attrs.country ) return `${indent}${content}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, this attribute is only used for razorpay-IN org and axis org.

Why is this not being used for Curlec?

@razortanmayshah razortanmayshah merged commit 85d5924 into main Apr 23, 2024
1 check passed
@razortanmayshah razortanmayshah deleted the DX-574-improve-search-experience-for-faq-and-tabs branch April 23, 2024 09:54
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

Successfully merging this pull request may close these issues.

None yet

2 participants