applesauce-content 0.0.0-next-20241108100553 → 0.0.0-next-20241112141526

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  export declare const Expressions: {
2
+ readonly link: RegExp;
2
3
  readonly cashu: RegExp;
3
4
  readonly nostrLink: RegExp;
4
5
  readonly emoji: RegExp;
@@ -1,4 +1,7 @@
1
1
  export const Expressions = {
2
+ get link() {
3
+ return /https?:\/\/([a-zA-Z0-9\.\-]+\.[a-zA-Z]+)([\/\?#][\p{L}\p{N}\p{M}&\.-\/\?=#\-@%\+_,:!~*]*)?/gu;
4
+ },
2
5
  get cashu() {
3
6
  return /(cashu(?:A|B)[A-Za-z0-9_-]{100,10000}={0,3})/gi;
4
7
  },
@@ -1,11 +1,13 @@
1
1
  export function eolMetadata() {
2
2
  return (tree) => {
3
3
  for (let i = 0; i < tree.children.length; i++) {
4
- // const node = tree.children[i];
4
+ const node = tree.children[i];
5
5
  const next = tree.children[i + 1];
6
- if (next && next.type === "text" && next.value.startsWith("\n")) {
7
- next.data = next.data || {};
8
- next.data.eol = true;
6
+ if ((node.type === "text" && node.value.endsWith("\n")) ||
7
+ !next ||
8
+ (next.type === "text" && next.value.startsWith("\n"))) {
9
+ node.data = node.data || {};
10
+ node.data.eol = true;
9
11
  }
10
12
  }
11
13
  };
@@ -7,9 +7,20 @@ import { createTextNoteATS } from "./parser.js";
7
7
  import { hashtags } from "./hashtag.js";
8
8
  import { galleries } from "./gallery.js";
9
9
  import { lightningInvoices } from "./lightning.js";
10
+ import { eolMetadata } from "../nast/eol-metadata.js";
11
+ import { links } from "./links.js";
10
12
  export const ParsedTextContentSymbol = Symbol.for("parsed-text-content");
11
13
  // default kind 1 transformers
12
- export const defaultTransformers = [nostrMentions, galleries, emojis, hashtags, lightningInvoices, cashuTokens];
14
+ export const defaultTransformers = [
15
+ links,
16
+ nostrMentions,
17
+ galleries,
18
+ emojis,
19
+ hashtags,
20
+ lightningInvoices,
21
+ cashuTokens,
22
+ eolMetadata,
23
+ ];
13
24
  /** Parsed and process a note with custom transformers */
14
25
  export function getParsedTextContent(event, content, transformers = defaultTransformers) {
15
26
  // process strings
@@ -1,4 +1,4 @@
1
- import { Transformer } from "unified";
1
+ import { type Transformer } from "unified";
2
2
  import { Root } from "../nast/types.js";
3
3
  /** Adds emoji tags to text ATS */
4
4
  export declare function emojis(): Transformer<Root>;
@@ -1,4 +1,5 @@
1
1
  export * from "./content.js";
2
+ export * from "./links.js";
2
3
  export * from "./mentions.js";
3
4
  export * from "./cashu.js";
4
5
  export * from "./emoji.js";
@@ -1,4 +1,5 @@
1
1
  export * from "./content.js";
2
+ export * from "./links.js";
2
3
  export * from "./mentions.js";
3
4
  export * from "./cashu.js";
4
5
  export * from "./emoji.js";
@@ -0,0 +1,3 @@
1
+ import { Transformer } from "unified";
2
+ import { Root } from "../nast/types.js";
3
+ export declare function links(): Transformer<Root>;
@@ -0,0 +1,22 @@
1
+ import Expressions from "../helpers/regexp.js";
2
+ import { findAndReplace } from "../nast/find-and-replace.js";
3
+ export function links() {
4
+ return (tree) => {
5
+ findAndReplace(tree, [
6
+ [
7
+ Expressions.link,
8
+ (_) => {
9
+ try {
10
+ return {
11
+ type: "link",
12
+ href: new URL(_).toString(),
13
+ value: _,
14
+ };
15
+ }
16
+ catch (error) { }
17
+ return false;
18
+ },
19
+ ],
20
+ ]);
21
+ };
22
+ }
@@ -0,0 +1,3 @@
1
+ import { Transformer } from "unified";
2
+ import { Root } from "../nast/types.js";
3
+ export declare function links(): Transformer<Root>;
@@ -0,0 +1,22 @@
1
+ import Expressions from "../helpers/regexp.js";
2
+ import { findAndReplace } from "../nast/find-and-replace.js";
3
+ export function links() {
4
+ return (tree) => {
5
+ findAndReplace(tree, [
6
+ [
7
+ Expressions.link,
8
+ (_) => {
9
+ try {
10
+ return {
11
+ type: "link",
12
+ href: new URL(_).toString(),
13
+ value: _,
14
+ };
15
+ }
16
+ catch (error) { }
17
+ return false;
18
+ },
19
+ ],
20
+ ]);
21
+ };
22
+ }
@@ -1,15 +1,13 @@
1
- import { tokenize } from "linkifyjs";
2
1
  /** Creates a {@link Root} ATS node for a text note */
3
2
  export function createTextNoteATS(event, content) {
4
- const tokens = tokenize(content || (typeof event === "string" ? event : event.content));
5
3
  return {
6
4
  type: "root",
7
5
  event: typeof event !== "string" ? event : undefined,
8
- children: tokens.map((token) => {
9
- if (token.isLink)
10
- return { type: "link", href: token.toHref(), value: token.toString() };
11
- else
12
- return { type: "text", value: token.v };
13
- }),
6
+ children: [
7
+ {
8
+ type: "text",
9
+ value: content || (typeof event === "string" ? event : event.content),
10
+ },
11
+ ],
14
12
  };
15
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-content",
3
- "version": "0.0.0-next-20241108100553",
3
+ "version": "0.0.0-next-20241112141526",
4
4
  "description": "Unified plugins for processing event content",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -40,8 +40,7 @@
40
40
  "@types/hast": "^3.0.4",
41
41
  "@types/mdast": "^4.0.4",
42
42
  "@types/unist": "^3.0.3",
43
- "applesauce-core": "0.0.0-next-20241108100553",
44
- "linkifyjs": "^4.1.3",
43
+ "applesauce-core": "0.0.0-next-20241112141526",
45
44
  "mdast-util-find-and-replace": "^3.0.1",
46
45
  "nostr-tools": "^2.10.1",
47
46
  "remark": "^15.0.1",