Merge pull request #356 from MidhunSureshR/linkify-doc
Add jsdoc comments for clickable link code + Minor Changes
This commit is contained in:
commit
df8686099f
3 changed files with 17 additions and 1 deletions
|
@ -1,5 +1,10 @@
|
||||||
import { linkify } from "./linkify/linkify.js";
|
import { linkify } from "./linkify/linkify.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse text into parts such as newline, links and text.
|
||||||
|
* @param {string} body A string to parse into parts
|
||||||
|
* @returns {MessageBody} Parsed result
|
||||||
|
*/
|
||||||
export function parsePlainBody(body) {
|
export function parsePlainBody(body) {
|
||||||
const parts = [];
|
const parts = [];
|
||||||
const lines = body.split("\n");
|
const lines = body.split("\n");
|
||||||
|
@ -16,7 +21,7 @@ export function parsePlainBody(body) {
|
||||||
for (let i = 0; i < lines.length; i += 1) {
|
for (let i = 0; i < lines.length; i += 1) {
|
||||||
const line = lines[i];
|
const line = lines[i];
|
||||||
if (line.length) {
|
if (line.length) {
|
||||||
linkify(lines[i], linkifyCallback);
|
linkify(line, linkifyCallback);
|
||||||
}
|
}
|
||||||
const isLastLine = i >= (lines.length - 1);
|
const isLastLine = i >= (lines.length - 1);
|
||||||
if (!isLastLine) {
|
if (!isLastLine) {
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
import { regex } from "./regex.js";
|
import { regex } from "./regex.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits text into links and non-links.
|
||||||
|
* For each such separated token, callback is called
|
||||||
|
* with the token and a boolean passed as argument.
|
||||||
|
* The boolean indicates whether the token is a link or not.
|
||||||
|
* @param {string} text Text to split
|
||||||
|
* @param {function(string, boolean)} callback A function to call with split tokens
|
||||||
|
*/
|
||||||
export function linkify(text, callback) {
|
export function linkify(text, callback) {
|
||||||
const matches = text.matchAll(regex);
|
const matches = text.matchAll(regex);
|
||||||
let curr = 0;
|
let curr = 0;
|
||||||
|
|
|
@ -28,6 +28,9 @@ export class TextMessageView extends TemplateView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map from part to function that outputs DOM for the part
|
||||||
|
*/
|
||||||
const formatFunction = {
|
const formatFunction = {
|
||||||
text: textPart => text(textPart.text),
|
text: textPart => text(textPart.text),
|
||||||
link: linkPart => tag.a({ href: linkPart.url, target: "_blank", rel: "noopener" }, [linkPart.text]),
|
link: linkPart => tag.a({ href: linkPart.url, target: "_blank", rel: "noopener" }, [linkPart.text]),
|
||||||
|
|
Reference in a new issue