@zulip/shared
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -80,2 +80,3 @@ import _ from "lodash"; | ||
} | ||
return undefined; | ||
} | ||
@@ -88,2 +89,3 @@ | ||
} | ||
return undefined; | ||
} | ||
@@ -93,3 +95,3 @@ | ||
// If the emoji name is a realm emoji, returns the URL for it. | ||
// Returns undefined for unicode emoji. | ||
// Returns undefined for Unicode emoji. | ||
// get_realm_emoji_url('shrug') === '/user_avatars/2/emoji/images/31.png' | ||
@@ -100,3 +102,3 @@ | ||
if (!data) { | ||
// Not all emojis have urls, plus the user | ||
// Not all emojis have URLs, plus the user | ||
// may have hand-typed an invalid emoji. | ||
@@ -107,3 +109,3 @@ // The caller can check the result for falsiness | ||
// whatever makes sense for the caller. | ||
return; | ||
return undefined; | ||
} | ||
@@ -204,3 +206,3 @@ | ||
// Our caller needs to handle this possibility. | ||
return; | ||
return undefined; | ||
} | ||
@@ -207,0 +209,0 @@ |
@@ -33,14 +33,30 @@ import katex from "katex"; | ||
export function wrap_code(code) { | ||
// We fill up the actual values when initializing. | ||
let pygments_data = {}; | ||
export function initialize(generated_pygments_data) { | ||
pygments_data = generated_pygments_data.langs; | ||
} | ||
export function wrap_code(code, lang) { | ||
let header = '<div class="codehilite"><pre><span></span><code>'; | ||
// Mimics the backend logic of adding a data-attribute (data-code-language) | ||
// to know what Pygments language was used to highlight this code block. | ||
// | ||
// NOTE: Clients like zulip-mobile wouldn't receive the pygments data since that comes from outside | ||
// the `/shared` folder. To handle such a case we check if pygments data is empty and fallback to | ||
// using the default header if it is. | ||
if (lang !== undefined && lang !== "" && Object.keys(pygments_data).length > 0) { | ||
const code_language = _.get(pygments_data, [lang, "pretty_name"], lang); | ||
header = `<div class="codehilite" data-code-language="${_.escape( | ||
code_language, | ||
)}"><pre><span></span><code>`; | ||
} | ||
// Trim trailing \n until there's just one left | ||
// This mirrors how pygments handles code input | ||
return ( | ||
'<div class="codehilite"><pre><span></span><code>' + | ||
_.escape(code.replace(/^\n+|\n+$/g, "")) + | ||
"\n</code></pre></div>\n" | ||
); | ||
return header + _.escape(code.replace(/^\n+|\n+$/g, "")) + "\n</code></pre></div>"; | ||
} | ||
function wrap_quote(text) { | ||
const paragraphs = text.split("\n\n"); | ||
const paragraphs = text.split("\n"); | ||
const quoted_paragraphs = []; | ||
@@ -52,11 +68,6 @@ | ||
const lines = paragraph.split("\n"); | ||
quoted_paragraphs.push( | ||
lines | ||
.filter((line) => line !== "") | ||
.map((line) => "> " + line) | ||
.join("\n"), | ||
); | ||
quoted_paragraphs.push(lines.map((line) => "> " + line).join("\n")); | ||
} | ||
return quoted_paragraphs.join("\n\n"); | ||
return quoted_paragraphs.join("\n"); | ||
} | ||
@@ -69,3 +80,3 @@ | ||
}); | ||
} catch (ex) { | ||
} catch { | ||
return '<span class="tex-error">' + _.escape(tex) + "</span>"; | ||
@@ -170,3 +181,3 @@ } | ||
} else { | ||
lines.push(line.trimRight()); | ||
lines.push(line.trimEnd()); | ||
} | ||
@@ -176,3 +187,3 @@ }, | ||
done() { | ||
const text = wrap_code(lines.join("\n")); | ||
const text = wrap_code(lines.join("\n"), lang); | ||
// insert safe HTML that is passed through the parsing | ||
@@ -179,0 +190,0 @@ const placeholder = stash_func(text, true); |
{ | ||
"name": "@zulip/shared", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26568
648
0