New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@progfay/scrapbox-parser

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@progfay/scrapbox-parser - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

2

lib/block/BlockComponent.js

@@ -6,5 +6,5 @@ "use strict";

const blockMatcher = block.match(/^\s*/);
const indent = blockMatcher ? blockMatcher[0].length : 0;
const indent = blockMatcher[0].length;
return { indent, text: block };
}));
//# sourceMappingURL=BlockComponent.js.map

@@ -5,3 +5,3 @@ import { BlockComponentType } from './BlockComponent';

type: 'codeBlock';
components: Array<BlockComponentType>;
components: BlockComponentType[];
};

@@ -8,0 +8,0 @@ export declare type CodeBlockType = {

@@ -6,14 +6,5 @@ "use strict";

const { components } = blockComponent;
const head = components.shift() || { indent: 0, text: '' };
const [head, ...body] = components;
const { indent, text } = head;
const match = text.match(/^\s*code:(.+)$/);
if (!match) {
return {
indent: 0,
type: 'codeBlock',
fileName: '',
content: ''
};
}
const fileName = match[1];
const fileName = text.replace(/^\s*code:/, '');
return {

@@ -23,4 +14,4 @@ indent,

fileName,
content: components
.map((blockComponent) => blockComponent.text.substring(indent + 1))
content: body
.map((component) => component.text.substring(indent + 1))
.join('\n')

@@ -27,0 +18,0 @@ };

@@ -6,3 +6,3 @@ import { PackedBlockComponentType } from './PackedBlockComponent';

export declare type BlockType = CodeBlockType | TableType | LineType;
export declare const convertToBlock: (packedBlockComponent: PackedBlockComponentType) => CodeBlockType | TableType | LineType | undefined;
export declare const convertToBlock: (packedBlockComponent: PackedBlockComponentType) => BlockType;
//# sourceMappingURL=index.d.ts.map

@@ -11,6 +11,4 @@ "use strict";

return Table_1.convertToTable(packedBlockComponent);
if (Line_1.isLineComponent(packedBlockComponent))
return Line_1.convertToLine(packedBlockComponent);
return undefined;
return Line_1.convertToLine(packedBlockComponent);
};
//# sourceMappingURL=index.js.map
import { BlockComponentType } from './BlockComponent';
import { PackedBlockComponentType } from './PackedBlockComponent';
import { LineNodeType } from './node';

@@ -11,6 +10,5 @@ export declare type LineComponentType = {

type: 'line';
nodes: Array<LineNodeType>;
nodes: LineNodeType[];
};
export declare const isLineComponent: (packedBlockComponent: PackedBlockComponentType) => packedBlockComponent is LineComponentType;
export declare const convertToLine: (lineComponent: LineComponentType) => LineType;
//# sourceMappingURL=Line.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_1 = require("./node");
exports.isLineComponent = (packedBlockComponent) => (packedBlockComponent.type === 'line');
exports.convertToLine = (lineComponent) => {

@@ -6,0 +5,0 @@ const { indent, text } = lineComponent.component;

@@ -1,3 +0,2 @@

export declare const codeRegExp: RegExp;
export declare const codeCommandRegExp: RegExp;
import { ParserType } from '.';
export declare type CodeNodeType = {

@@ -7,3 +6,3 @@ type: 'code';

};
export declare const createCodeNode: (text: string) => CodeNodeType;
export declare const CodeNodeParser: ParserType;
//# sourceMappingURL=CodeNode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.codeRegExp = /^(.*?)`(.*?)`(.*)$/;
exports.codeCommandRegExp = /^(\$ .+)$/;
exports.createCodeNode = (text) => ({
const _1 = require(".");
const codeRegExp = /^(.*?)`(.*?)`(.*)$/;
const codeCommandRegExp = /^(\$ .+)$/;
const createCodeNode = (text) => ({
type: 'code',
text
});
exports.CodeNodeParser = (text, { nested, quoted }, next) => {
if (nested)
return next();
const codeCommandMatch = text.match(codeCommandRegExp);
if (codeCommandMatch) {
const [, target] = codeCommandMatch;
return [createCodeNode(target)];
}
const codeMatch = text.match(codeRegExp);
if (codeMatch) {
const [, left, target, right] = codeMatch;
return [
..._1.convertToLineNodes(left, { nested, quoted }),
createCodeNode(target),
..._1.convertToLineNodes(right, { nested, quoted })
];
}
return next();
};
//# sourceMappingURL=CodeNode.js.map

@@ -1,12 +0,11 @@

import { LineNodeType } from '.';
import { ParserType, LineNodeType } from '.';
export declare type DecorationCharType = '*' | '!' | '"' | '#' | '%' | '&' | '\'' | '(' | ')' | '+' | ',' | '-' | '.' | '/' | '{' | '|' | '}' | '<' | '>' | '_' | '~';
export declare type AsteriskDecorationCharType = '*-1' | '*-2' | '*-3' | '*-4' | '*-5' | '*-6' | '*-7' | '*-8' | '*-9' | '*-10';
export declare type DecorationType = Exclude<DecorationCharType, '*'> | AsteriskDecorationCharType;
export declare const decorationRegExp: RegExp;
export declare type DecorationNodeType = {
type: 'decoration';
decos: Array<DecorationType>;
nodes: Array<LineNodeType>;
decos: DecorationType[];
nodes: LineNodeType[];
};
export declare const createDecorationNode: (decoChars: string, nodes: LineNodeType[]) => DecorationNodeType;
export declare const DecorationNodeParser: ParserType;
//# sourceMappingURL=DecorationNode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decorationRegExp = /^(.*?)\[([!"#%&'()*+,-./{|}<>_~]+) ((?:\[[^\]]+\]|[^\]])+)\](.*)$/;
exports.createDecorationNode = (decoChars, nodes) => {
const _1 = require(".");
const decorationRegExp = /^(.*?)\[([!"#%&'()*+,-./{|}<>_~]+) ((?:\[[^\]]+\]|[^\]])+)\](.*)$/;
const createDecorationNode = (decoChars, nodes) => {
const decoSet = new Set(decoChars);

@@ -17,2 +18,15 @@ if (decoSet.has('*')) {

};
exports.DecorationNodeParser = (text, { nested, quoted }, next) => {
if (nested)
return next();
const decorationMatch = text.match(decorationRegExp);
if (!decorationMatch)
return next();
const [, left, decoChars, target, right] = decorationMatch;
return [
..._1.convertToLineNodes(left, { nested, quoted }),
createDecorationNode(decoChars, _1.convertToLineNodes(target, { nested: true, quoted })),
..._1.convertToLineNodes(right, { nested, quoted })
];
};
//# sourceMappingURL=DecorationNode.js.map

@@ -1,2 +0,2 @@

export declare const hashTagRegExp: RegExp;
import { ParserType } from '.';
export declare type HashTagNodeType = {

@@ -6,3 +6,3 @@ type: 'hashTag';

};
export declare const createHashTagNode: (href: string) => HashTagNodeType;
export declare const HashTagNodeParser: ParserType;
//# sourceMappingURL=HashTagNode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hashTagRegExp = /^(.+? )?#(\S+)(.*)?$/;
exports.createHashTagNode = (href) => ({
const _1 = require(".");
const hashTagRegExp = /^(.+? )?#(\S+)(.*)?$/;
const createHashTagNode = (href) => ({
type: 'hashTag',
href
});
exports.HashTagNodeParser = (text, { nested, quoted }, next) => {
if (nested)
return next();
const hashTagMatch = text.match(hashTagRegExp);
if (!hashTagMatch)
return next();
const [, left, target, right] = hashTagMatch;
return [
..._1.convertToLineNodes(left, { nested, quoted }),
createHashTagNode(target),
..._1.convertToLineNodes(right, { nested, quoted })
];
};
//# sourceMappingURL=HashTagNode.js.map

@@ -1,2 +0,2 @@

export declare const iconRegExp: RegExp;
import { ParserType } from '.';
export declare type IconNodeType = {

@@ -7,3 +7,3 @@ type: 'icon';

};
export declare const createIconNode: (path: string) => IconNodeType | null;
export declare const IconNodeParser: ParserType;
//# sourceMappingURL=IconNode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.iconRegExp = /^(.*?)\[(.*)\.icon(\*(\d+))?\](.*)$/;
exports.createIconNode = (path) => ({
const _1 = require(".");
const iconRegExp = /^(.*?)\[(.*)\.icon(\*(\d+))?\](.*)$/;
const createIconNode = (path) => ({
type: 'icon',

@@ -9,2 +10,16 @@ pathType: /^\//.test(path) ? 'root' : 'relative',

});
exports.IconNodeParser = (text, { nested, quoted }, next) => {
if (nested)
return next();
const iconMatch = text.match(iconRegExp);
if (!iconMatch)
return next();
const [, left, path, , num = '1', right] = iconMatch;
const iconNode = createIconNode(path);
return [
..._1.convertToLineNodes(left, { nested, quoted }),
...new Array(parseInt(num, 10)).fill(iconNode),
..._1.convertToLineNodes(right, { nested, quoted })
];
};
//# sourceMappingURL=IconNode.js.map

@@ -11,6 +11,9 @@ import { QuoteNodeType } from './QuoteNode';

export declare type LineNodeType = QuoteNodeType | StrongNodeType | DecorationNodeType | CodeNodeType | UrlNodeType | InternalLinkNodeType | IconNodeType | HashTagNodeType | PlainNodeType;
export declare const convertToLineNodes: (text: string, { nested, quoted }?: {
export declare type ParserOptionType = {
nested: boolean;
quoted: boolean;
}) => LineNodeType[];
};
export declare type NextParserType = () => LineNodeType[];
export declare type ParserType = (text: string, opt: ParserOptionType, next: NextParserType) => LineNodeType[];
export declare const convertToLineNodes: (text?: string, opt?: ParserOptionType) => LineNodeType[];
//# sourceMappingURL=index.d.ts.map

@@ -12,98 +12,11 @@ "use strict";

const PlainNode_1 = require("./PlainNode");
exports.convertToLineNodes = (text, { nested, quoted } = { nested: false, quoted: false }) => {
const FalsyEliminator = (text, _opt, next) => {
if (!text)
return [];
if (!nested && !quoted) {
const quoteMatch = text.match(QuoteNode_1.quoteRegExp);
if (quoteMatch) {
const [, target] = quoteMatch;
const nodes = exports.convertToLineNodes(target, { nested, quoted: true });
return [QuoteNode_1.createQuoteNode(nodes)];
}
}
if (!nested) {
const codeCommandMatch = text.match(CodeNode_1.codeCommandRegExp);
if (codeCommandMatch) {
const [, target] = codeCommandMatch;
return [CodeNode_1.createCodeNode(target)];
}
const codeMatch = text.match(CodeNode_1.codeRegExp);
if (codeMatch) {
const [, left, target, right] = codeMatch;
return [
...exports.convertToLineNodes(left, { nested, quoted }),
CodeNode_1.createCodeNode(target),
...exports.convertToLineNodes(right, { nested, quoted })
];
}
const strongMatch = text.match(StrongNode_1.strongRegExp);
if (strongMatch) {
const [, left, target, right] = strongMatch;
return [
...exports.convertToLineNodes(left, { nested, quoted }),
StrongNode_1.createStrongNode(exports.convertToLineNodes(target, { nested: true, quoted })),
...exports.convertToLineNodes(right, { nested, quoted })
];
}
const decorationMatch = text.match(DecorationNode_1.decorationRegExp);
if (decorationMatch) {
const [, left, decoChars, target, right] = decorationMatch;
return [
...exports.convertToLineNodes(left, { nested, quoted }),
DecorationNode_1.createDecorationNode(decoChars, exports.convertToLineNodes(target, { nested: true, quoted })),
...exports.convertToLineNodes(right, { nested, quoted })
];
}
}
const UrlMatch = text.match(UrlNode_1.urlRegExp) ||
text.match(UrlNode_1.leftUrlRegExp) ||
text.match(UrlNode_1.rightUrlRegExp);
if (UrlNode_1.isUrlMatch(UrlMatch)) {
const [, left, , , right] = UrlMatch;
const { href, content = '' } = UrlMatch.groups;
return [
...exports.convertToLineNodes(left, { nested, quoted }),
UrlNode_1.createUrlNode(href, content),
...exports.convertToLineNodes(right, { nested, quoted })
];
}
const iconMatch = text.match(IconNode_1.iconRegExp);
if (iconMatch) {
const [, left, path, , num = '1', right] = iconMatch;
const iconNode = IconNode_1.createIconNode(path);
return [
...exports.convertToLineNodes(left, { nested, quoted }),
...new Array(parseInt(num)).fill(iconNode),
...exports.convertToLineNodes(right, { nested, quoted })
];
}
const internalLinkMatch = text.match(InternalLinkNode_1.internalLinkRegExp);
if (internalLinkMatch) {
const [, left, target, right] = internalLinkMatch;
return [
...exports.convertToLineNodes(left, { nested, quoted }),
InternalLinkNode_1.createInternalLinkNode(target),
...exports.convertToLineNodes(right, { nested, quoted })
];
}
const httpMatch = text.match(UrlNode_1.httpRegExp);
if (httpMatch) {
const [, left, target, right] = httpMatch;
return [
...exports.convertToLineNodes(left, { nested, quoted }),
UrlNode_1.createUrlNode(target, ''),
...exports.convertToLineNodes(right, { nested, quoted })
];
}
const hashTagMatch = text.match(HashTagNode_1.hashTagRegExp);
if (hashTagMatch) {
const [, left, target, right] = hashTagMatch;
return [
...exports.convertToLineNodes(left, { nested, quoted }),
HashTagNode_1.createHashTagNode(target),
...exports.convertToLineNodes(right, { nested, quoted })
];
}
return [PlainNode_1.createPlainNode(text)];
return next();
};
const combineNodeParsers = (...parsers) => {
return (text = '', opt = { nested: false, quoted: false }) => (parsers.slice().reverse().reduce((acc, parser) => () => parser(text, opt, acc), () => PlainNode_1.PlainNodeParser(text))());
};
exports.convertToLineNodes = combineNodeParsers(FalsyEliminator, QuoteNode_1.QuoteNodeParser, CodeNode_1.CodeNodeParser, StrongNode_1.StrongNodeParser, UrlNode_1.UrlNodeParser, DecorationNode_1.DecorationNodeParser, IconNode_1.IconNodeParser, InternalLinkNode_1.InternalLinkNodeParser, HashTagNode_1.HashTagNodeParser);
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

export declare const internalLinkRegExp: RegExp;
import { ParserType } from '.';
export declare type InternalLinkNodeType = {

@@ -7,3 +7,3 @@ type: 'link';

};
export declare const createInternalLinkNode: (href: string) => InternalLinkNodeType;
export declare const InternalLinkNodeParser: ParserType;
//# sourceMappingURL=InternalLinkNode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.internalLinkRegExp = /^(.*?)\[(\/?[^[\]]+)\](.*)$/;
exports.createInternalLinkNode = (href) => ({
const _1 = require(".");
const internalLinkRegExp = /^(.*?)\[(\/?[^[\]]+)\](.*)$/;
const createInternalLinkNode = (href) => ({
type: 'link',

@@ -9,2 +10,13 @@ pathType: /^\/.*$/.test(href) ? 'root' : 'relative',

});
exports.InternalLinkNodeParser = (text, { nested, quoted }, next) => {
const internalLinkMatch = text.match(internalLinkRegExp);
if (!internalLinkMatch)
return next();
const [, left, target, right] = internalLinkMatch;
return [
..._1.convertToLineNodes(left, { nested, quoted }),
createInternalLinkNode(target),
..._1.convertToLineNodes(right, { nested, quoted })
];
};
//# sourceMappingURL=InternalLinkNode.js.map

@@ -0,1 +1,2 @@

import { LineNodeType } from '.';
export declare type PlainNodeType = {

@@ -6,2 +7,3 @@ type: 'plain';

export declare const createPlainNode: (text: string) => PlainNodeType;
export declare const PlainNodeParser: (text: string) => LineNodeType[];
//# sourceMappingURL=PlainNode.d.ts.map

@@ -5,4 +5,7 @@ "use strict";

type: 'plain',
text: text
text
});
exports.PlainNodeParser = (text) => {
return [exports.createPlainNode(text)];
};
//# sourceMappingURL=PlainNode.js.map

@@ -1,8 +0,7 @@

import { LineNodeType } from '.';
export declare const quoteRegExp: RegExp;
import { ParserType, LineNodeType } from '.';
export declare type QuoteNodeType = {
type: 'quote';
nodes: Array<LineNodeType>;
nodes: LineNodeType[];
};
export declare const createQuoteNode: (nodes: LineNodeType[]) => QuoteNodeType;
export declare const QuoteNodeParser: ParserType;
//# sourceMappingURL=QuoteNode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.quoteRegExp = /^>(.*)$/;
exports.createQuoteNode = (nodes) => ({
const _1 = require(".");
const quoteRegExp = /^>(.*)$/;
const createQuoteNode = (text) => ({
type: 'quote',
nodes
nodes: _1.convertToLineNodes(text, { nested: false, quoted: true })
});
exports.QuoteNodeParser = (text, { nested, quoted }, next) => {
if (nested || quoted)
return next();
const quoteMatch = text.match(quoteRegExp);
if (!quoteMatch)
return next();
const [, target] = quoteMatch;
return [createQuoteNode(target)];
};
//# sourceMappingURL=QuoteNode.js.map

@@ -1,8 +0,7 @@

import { LineNodeType } from '.';
export declare const strongRegExp: RegExp;
import { ParserType, LineNodeType } from '.';
export declare type StrongNodeType = {
type: 'strong';
nodes: Array<LineNodeType>;
nodes: LineNodeType[];
};
export declare const createStrongNode: (nodes: LineNodeType[]) => StrongNodeType;
export declare const StrongNodeParser: ParserType;
//# sourceMappingURL=StrongNode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.strongRegExp = /^(.*?)\[\[(.+?[\]]*)\]\](.*)$/;
exports.createStrongNode = (nodes) => ({
const _1 = require(".");
const strongRegExp = /^(.*?)\[\[(.+?[\]]*)\]\](.*)$/;
const createStrongNode = (nodes) => ({
type: 'strong',
nodes
});
exports.StrongNodeParser = (text, { nested, quoted }, next) => {
if (nested)
return next();
const strongMatch = text.match(strongRegExp);
if (!strongMatch)
return next();
const [, left, target, right] = strongMatch;
return [
..._1.convertToLineNodes(left, { nested, quoted }),
createStrongNode(_1.convertToLineNodes(target, { nested: true, quoted })),
..._1.convertToLineNodes(right, { nested, quoted })
];
};
//# sourceMappingURL=StrongNode.js.map

@@ -6,3 +6,3 @@ export declare type ImageNodeType = {

};
export declare const createImageNode: (src: string, link?: string) => ImageNodeType;
export declare const createImageNode: (src: string, link: string) => ImageNodeType;
//# sourceMappingURL=ImageNode.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createImageNode = (src, link = '') => {
exports.createImageNode = (src, link) => {
if (/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(src)) {

@@ -5,0 +5,0 @@ src = src + '/thumb/1000';

@@ -0,10 +1,8 @@

import { ParserType } from '../';
import { ExternalLinkNodeType } from './ExternalLinkNode';
import { ImageNodeType } from './ImageNode';
export declare const httpRegExp: RegExp;
export declare const urlRegExp: RegExp;
export declare const leftUrlRegExp: RegExp;
export declare const rightUrlRegExp: RegExp;
export declare type UrlNodeType = ExternalLinkNodeType | ImageNodeType;
declare type UrlMatchType = {
groups: {
left: string;
right: string;
href: string;

@@ -15,4 +13,5 @@ content: string;

export declare const isUrlMatch: (obj: any) => obj is UrlMatchType;
export declare const createUrlNode: (href: string, content?: string) => UrlNodeType;
export declare type UrlNodeType = ExternalLinkNodeType | ImageNodeType;
export declare const UrlNodeParser: ParserType;
export {};
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("../");
const ExternalLinkNode_1 = require("./ExternalLinkNode");
const ImageNode_1 = require("./ImageNode");
exports.httpRegExp = /^(.*?)(https?:\/\/[^\s\]]+)(.*)$/;
exports.urlRegExp = /^(.*?)\[(?<href>https?:\/\/[^\s\]]+)(?<content>)\](.*)$/;
exports.leftUrlRegExp = /^(.*?)\[(?<href>https?:\/\/[^\s\]]+)\s+(?<content>[^\]]*[^\s])\](.*)$/;
exports.rightUrlRegExp = /^(.*?)\[(?<content>[^\]]*[^\s])\s+(?<href>https?:\/\/[^\s\]]+)\](.*)$/;
const urlRegExp = /^(?<left>.*?)\[(?<href>https?:\/\/[^\s\]]+)(?<content>)\](?<right>.*)$/;
const leftUrlRegExp = /^(?<left>.*?)\[(?<href>https?:\/\/[^\s\]]+)\s+(?<content>[^\]]*[^\s])\](?<right>.*)$/;
const rightUrlRegExp = /^(?<left>.*?)\[(?<content>[^\]]*[^\s])\s+(?<href>https?:\/\/[^\s\]]+)\](?<right>.*)$/;
const httpRegExp = /^(?<left>.*?\s)?(?<href>https?:\/\/[^\s\]]+)(?<content>)(?<right>.*)$/;
exports.isUrlMatch = (obj) => (obj && obj.groups && obj.groups.href);

@@ -13,15 +14,25 @@ const isUrl = (text) => (/^https?:\/\/[^\s\]]+$/.test(text));

const isGyazoImageUrl = (text) => (/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(text));
exports.createUrlNode = (href, content = '') => {
if (content === '')
return isImageUrl(href) ? ImageNode_1.createImageNode(href, content) : ExternalLinkNode_1.createExternalLinkNode(href, content);
if (content && !isUrl(content))
const createUrlNode = (href, content) => {
if (!isUrl(content) && !isImageUrl(href))
return ExternalLinkNode_1.createExternalLinkNode(href, content);
if (isGyazoImageUrl(content))
return ImageNode_1.createImageNode(content, href);
if (isGyazoImageUrl(href))
return ImageNode_1.createImageNode(href, content);
if (isImageUrl(content))
return ImageNode_1.createImageNode(content, href);
[href, content] = [content, href];
return ImageNode_1.createImageNode(href, content);
};
exports.UrlNodeParser = (text, { nested, quoted }, next) => {
if (nested)
return next();
const UrlMatch = text.match(urlRegExp) ||
text.match(leftUrlRegExp) ||
text.match(rightUrlRegExp) ||
text.match(httpRegExp);
if (!exports.isUrlMatch(UrlMatch))
return next();
const { left, href, content, right } = UrlMatch.groups;
return [
...__1.convertToLineNodes(left, { nested, quoted }),
createUrlNode(href, content),
...__1.convertToLineNodes(right, { nested, quoted })
];
};
//# sourceMappingURL=index.js.map

@@ -5,62 +5,35 @@ "use strict";

const packedBlockComponents = [];
let codeBlockComponents = [];
let tableComponents = [];
while (blockComponents.length > 0) {
const blockComponent = blockComponents.shift();
if (!blockComponent)
continue;
let packingComponent = null;
for (const blockComponent of blockComponents) {
const { indent, text } = blockComponent;
if (codeBlockComponents.length > 0) {
if (indent > codeBlockComponents[0].indent) {
codeBlockComponents.push(blockComponent);
if (packingComponent) {
if (indent > packingComponent.indent) {
packingComponent.components.push(blockComponent);
continue;
}
else {
packedBlockComponents.push({
type: 'codeBlock',
components: codeBlockComponents
});
codeBlockComponents = [];
packedBlockComponents.push(packingComponent);
packingComponent = null;
}
}
if (tableComponents.length > 0) {
if (indent > tableComponents[0].indent) {
tableComponents.push(blockComponent);
continue;
}
else {
packedBlockComponents.push({
type: 'table',
components: tableComponents
});
tableComponents = [];
}
const isCodeBlock = text.match(/^\s*code:(.+)$/);
const isTable = text.match(/^\s*table:(.+)$/);
if (isCodeBlock || isTable) {
packingComponent = {
type: isCodeBlock ? 'codeBlock' : 'table',
components: [blockComponent],
indent
};
}
if (text.match(/^\s*code:(.+)$/)) {
codeBlockComponents.push(blockComponent);
continue;
else {
packedBlockComponents.push({
type: 'line',
component: blockComponent
});
}
if (text.match(/^\s*table:(.+)$/)) {
tableComponents.push(blockComponent);
continue;
}
packedBlockComponents.push({
type: 'line',
component: blockComponent
});
}
if (codeBlockComponents.length > 0) {
packedBlockComponents.push({
type: 'codeBlock',
components: codeBlockComponents
});
}
if (tableComponents.length > 0) {
packedBlockComponents.push({
type: 'table',
components: tableComponents
});
}
if (packingComponent)
packedBlockComponents.push(packingComponent);
return packedBlockComponents;
};
//# sourceMappingURL=PackedBlockComponent.js.map
import { BlockComponentType } from './BlockComponent';
import { PackedBlockComponentType } from './PackedBlockComponent';
import { LineNodeType } from './node';
export declare type TableComponentType = {
type: 'table';
components: Array<BlockComponentType>;
components: BlockComponentType[];
};

@@ -11,6 +12,6 @@ export declare type TableType = {

fileName: string;
cells: Array<Array<string>>;
cells: LineNodeType[][][];
};
export declare const isTableComponent: (packedBlockComponent: PackedBlockComponentType) => packedBlockComponent is TableComponentType;
export declare const isTableComponent: (component: PackedBlockComponentType) => component is TableComponentType;
export declare const convertToTable: (tableComponent: TableComponentType) => TableType;
//# sourceMappingURL=Table.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTableComponent = (packedBlockComponent) => (packedBlockComponent.type === 'table');
const node_1 = require("./node");
exports.isTableComponent = (component) => (component.type === 'table');
exports.convertToTable = (tableComponent) => {
const { components } = tableComponent;
const head = components.shift() || { indent: 0, text: '' };
const [head, ...body] = components;
const { indent, text } = head;
const match = text.match(/^\s*table:(.+)$/);
if (!match) {
return {
indent: 0,
type: 'table',
fileName: '',
cells: []
};
}
const fileName = match[1];
const fileName = text.replace(/^\s*table:/, '');
return {

@@ -22,7 +14,9 @@ indent,

fileName,
cells: components
cells: body
.map((blockComponent) => blockComponent.text.substring(indent + 1))
.map((block) => block.split('\t'))
.map((text) => text
.split('\t')
.map((block) => node_1.convertToLineNodes(block, { nested: true, quoted: false })))
};
};
//# sourceMappingURL=Table.js.map

@@ -5,3 +5,3 @@ import { BlockType } from './block';

title: string;
blocks: Array<BlockType>;
blocks: BlockType[];
};

@@ -8,0 +8,0 @@ export declare const convertToBlocks: (blockComponents: BlockComponentType[]) => BlockType[];

@@ -8,11 +8,9 @@ "use strict";

const packedBlockComponents = PackedBlockComponent_1.packBlockComponents(blockComponents);
return packedBlockComponents
.map(block_1.convertToBlock)
.filter((block) => Boolean(block));
return packedBlockComponents.map(block_1.convertToBlock);
};
const parse = (input) => {
const blockComponents = BlockComponent_1.convertToBlockComponents(input.trim());
const firstBlock = blockComponents.shift() || { indent: 0, text: '' };
const title = firstBlock.text || 'Untitled';
const blocks = exports.convertToBlocks(blockComponents);
const [firstBlock, ...body] = blockComponents;
const title = firstBlock && firstBlock.text ? firstBlock.text : 'Untitled';
const blocks = exports.convertToBlocks(body);
return { title, blocks };

@@ -19,0 +17,0 @@ };

{
"name": "@progfay/scrapbox-parser",
"version": "1.2.0",
"version": "1.3.0",
"description": "parse Scrapbox notation to JavaScript Object",
"files": [
"lib"
],
"main": "./lib/index.js",

@@ -13,2 +16,3 @@ "types": "./lib/index.d.ts",

"test:update": "jest --updateSnapshot",
"coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"lint": "eslint . --ext .ts",

@@ -49,19 +53,2 @@ "lint:fix": "eslint --fix . --ext .ts"

"dependencies": {},
"jest": {
"moduleFileExtensions": [
"ts",
"js"
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.json"
}
},
"testMatch": [
"**/tests/**/*.test.ts"
]
},
"publishConfig": {

@@ -68,0 +55,0 @@ "access": "public"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc