How to use upad-parse - 10 common examples

To help you get started, we’ve selected a few upad-parse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MicroPad / Web / src / webV3 / src / epics / NotepadEpics.ts View on Github external
switchMap((action: Action) => {
			try {
				Parser.parse(action.payload, ['asciimath']);
			} catch (err) {
				alert(`Error reading file`);
				console.error(err);
				throw err;
			}

			return fromPromise(new Promise(resolve => {
				const notepad: INotepad = Parser.notepad;

				// Sort out assets
				Parser.parseAssets(action.payload, async (assets: IAssets) => {
					const notepadAssets = new Set((notepad.notepadAssets || []));
					for (let i = 0; i < assets.assets.length; i++) {
						if (!notepadAssets.has(assets.assets[i].uuid)) notepadAssets.add(assets.assets[i].uuid);
						await ASSET_STORAGE.setItem(assets.assets[i].uuid, assets.assets[i].data);
					}
github MicroPad / Web / app / src / react-web / SyncWorker.js View on Github external
export async function toSyncedNotepad(notepad) {
	// Setup access to our binary assets
	const ASSET_STORAGE = localforage.createInstance({
		name: 'MicroPad',
		storeName: 'assets'
	});
	await ASSET_STORAGE.ready();

	const assetHashes = {};

	notepad = await Translators.Json.toNotepadFromNotepad(notepad);
	const npAssets = Array.from(getUsedAssets(notepad.flatten()));

	// Get assets from storage as base64
	const base64Assets = await Promise.all((await Promise.all(npAssets.map(uuid => ASSET_STORAGE.getItem(uuid))))
		.map((blob) => {
			try {
				return getAsBase64(blob);
			} catch (e) {
				return null;
			}
		}));

	// Build up the asset list
	base64Assets
		.filter(base64 => !!base64 && base64.length > 0)
		.map(base64 => md5(base64))
github MicroPad / Web / app / src / react-web / DifferenceEngine.ts View on Github external
export const uploadNotepad = (username: string, token: string, syncId: string, notepad: ISyncedNotepad, passkey?: string): Observable =>
			from(!!notepad.crypto && !!passkey ? encrypt(notepad, passkey) : of(notepad)).pipe(
				concatMap(np =>
					call<{ assetsToUpload: AssetList }>('upload', syncId, {
						notepadV2: JSON.stringify(np, (k, v) => (k === 'parent') ? undefined : v) // Remove parent links here, unneeded content
							.replace(
								/[\u007f-\uffff]/g,
								char => '\\u' + ('0000' + char.charCodeAt(0).toString(16)).slice(-4)
							), // Fix unicode encoding
						username,
						token
					})
				),
				map(res => res.assetsToUpload)
			);
github MicroPad / Web / src / webV3 / src / epics / NotepadEpics.ts View on Github external
return fromPromise(new Promise(resolve => {
				const notepad: INotepad = Parser.notepad;

				// Sort out assets
				Parser.parseAssets(action.payload, async (assets: IAssets) => {
					const notepadAssets = new Set((notepad.notepadAssets || []));
					for (let i = 0; i < assets.assets.length; i++) {
						if (!notepadAssets.has(assets.assets[i].uuid)) notepadAssets.add(assets.assets[i].uuid);
						await ASSET_STORAGE.setItem(assets.assets[i].uuid, assets.assets[i].data);
					}

					notepad.notepadAssets = Array.from(notepadAssets);
					resolve(notepad);
				});
			}));
		}),
github MicroPad / Web / src / webV3 / src / epics / NotepadEpics.ts View on Github external
return fromPromise(new Promise(resolve => {
				const notepad: INotepad = Parser.notepad;

				// Sort out assets
				Parser.parseAssets(action.payload, async (assets: IAssets) => {
					const notepadAssets = new Set((notepad.notepadAssets || []));
					for (let i = 0; i < assets.assets.length; i++) {
						if (!notepadAssets.has(assets.assets[i].uuid)) notepadAssets.add(assets.assets[i].uuid);
						await ASSET_STORAGE.setItem(assets.assets[i].uuid, assets.assets[i].data);
					}

					notepad.notepadAssets = Array.from(notepadAssets);
					resolve(notepad);
				});
			}));
		}),
github MicroPad / Web / app / src / react-web / SearchWorker.ts View on Github external
await NOTEPAD_STORAGE.iterate((json: string) => {
		let shell: NotepadShell;
		try {
			shell = JSON.parse(json);
		} catch (ignored) {
			return;
		}

		notepads.push(
			Translators.Json.toFlatNotepadFromNotepad(shell, passkeys[shell.title])
				.catch(e =>
					console.warn(`Couldn't parse notepad: ${e}`)
				)
		);
		return;
	});
github MicroPad / Web / app / src / react-web / components / note-viewer / elements / JupyterInserterComponent.tsx View on Github external
readFileInputEventAsText(event).then(json => {
			insertElement({
				type: 'markdown',
				args: {} as ElementArgs,
				content: Translators.Json.toMarkdownFromJupyter(json)
			});
		}).catch(err => {
			console.error(err);
github MicroPad / Web / src / webV3 / src / epics / NotepadEpics.ts View on Github external
map((json: string) => {
			try {
				const res = JSON.parse(json);
				const notepad: INotepad = Parser.restoreNotepad(res);
				notepad.notepadAssets = res.notepadAssets;

				return actions.parseNpx.done({
					params: '',
					result: notepad
				});
			} catch (err) {
				alert(`Error restoring notepad`);
				console.error(err);
				return actions.parseNpx.failed({
					params: '',
					error: err
				});
			}
		})
	);
github MicroPad / Web / app / src / react-web / components / WhatsNewModalComponent.tsx View on Github external
private getHtml: () => Promise = async () => {
		const whatsNewNote = (await Translators.Xml.toNotepadFromNpx(helpNpx)).sections[0].notes[2];

		extension('colour', {
			type: 'listener',
			listeners: {
				'images.after': (event, text: string) =>
					text.replace(/c\[([^\]]+)]\(([^)]+)\)/gi, (match, content, colour) =>
						`<span style="color: ${colour}">${content}</span>`
					)
			}
		} as any);

		const html = new Converter({
			parseImgDimensions: true,
			simplifiedAutoLink: true,
			strikethrough: true,
			tables: true,
github MicroPad / Web / src / webV3 / src / components / note-viewer / elements / markdown / MarkdownHelpComponent.tsx View on Github external
render() {
		Parser.parse(helpNpx, ['asciimath']);
		const help: INotepad = Parser.notepad;
		const mdGuide = help.sections[1].notes[0];

		extension('mock', () =&gt; {
			let matches: string[] = [];
			return [
				{
					type: 'lang',
					regex: /(===([^]+?)===|''([^]+?)''|;;([^]+?);;)/gi,
					replace: function(s: string, match: string) {
						matches.push('&lt;Maths won\'t display in this view. See the help notepad.&gt;<br>' + match);
						let n = matches.length - 1;
						return '%ph' + n + 'ph%';
					}
				},
				{
					type: 'output',