Skip to content

Commit

Permalink
feat(migrate): Integrate a command to migrate from V1 to V2 note cont…
Browse files Browse the repository at this point in the history
…ent for file import.
  • Loading branch information
makaanneo committed Nov 24, 2022
1 parent 3b7138d commit e1ad694
Show file tree
Hide file tree
Showing 47 changed files with 2,124 additions and 149 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ And copy PDF files inside the import path to start working.
## How it works
These plugin imort files from certain folders, specified inside the settings. For pdf files it will extract some meta data if there as well as text stored inside the pdf (OCR must be done by the scanner application) and stores the text inside a comment block of the note itself.

## Format in Note



## Old style (Add function to auto migrate)

```xml
<!--
PDFMETADATATEXTSTART
Expand Down Expand Up @@ -71,6 +77,8 @@ Basically, this plugin is inspired by:
- [Resource Search Plugin](https://github.com/roman-r-m/joplin-plugin-resource-search)
- [Hotfolder](https://github.com/JackGruber/joplin-plugin-hotfolder)
- [Enhancement](https://github.com/SeptemberHX/joplin-plugin-enhancement)
- [Folding in Code Mirror Editor](https://github.com/ambrt/joplin-plugin-fold-cm)
- [Zettlr](https://www.zettlr.com/)

## Development

Expand Down
20 changes: 10 additions & 10 deletions api/JoplinData.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import { Path } from './types';
* ```
*/
export default class JoplinData {
private api_;
private pathSegmentRegex_;
private serializeApiBody;
private pathToString;
get(path: Path, query?: any): Promise<any>;
post(path: Path, query?: any, body?: any, files?: any[]): Promise<any>;
put(path: Path, query?: any, body?: any, files?: any[]): Promise<any>;
delete(path: Path, query?: any): Promise<any>;
itemType(itemId: string): Promise<ModelType>;
resourcePath(resourceId: string): Promise<string>;
private api_;
private pathSegmentRegex_;
private serializeApiBody;
private pathToString;
get(path: Path, query?: any): Promise<any>;
post(path: Path, query?: any, body?: any, files?: any[]): Promise<any>;
put(path: Path, query?: any, body?: any, files?: any[]): Promise<any>;
delete(path: Path, query?: any): Promise<any>;
itemType(itemId: string): Promise<ModelType>;
resourcePath(resourceId: string): Promise<string>;
}
8 changes: 2 additions & 6 deletions bump-plugin-version.js → bump-plugin-version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
import fs from 'fs-extra';

console.log('process.argv', process.argv);

Expand All @@ -10,9 +10,5 @@ function bumpVersion(manifestPath, destPath, version) {
}

if (process.argv.length > 2) {
bumpVersion(
'src/manifest.json',
'src/manifest.json',
process.argv[2]
);
bumpVersion('src/manifest.json', 'src/manifest.json', process.argv[2]);
}
1 change: 0 additions & 1 deletion emptyContentScript.js

This file was deleted.

1 change: 1 addition & 0 deletions emptyContentScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('nothing!');
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"prettier-format": "prettier --config .prettierrc src/**/*.ts --write",
"lint": "eslint . --ext .ts",
"test": "jest",
"bump-plugin-version": "node bump-plugin-version.js"
"bump-plugin-version": "ts-node bump-plugin-version.ts"
},
"license": "MIT",
"keywords": [
Expand Down Expand Up @@ -47,6 +47,7 @@
"buffer": "^6.0.3",
"canvas": "^2.10.1",
"chalk": "^4.0.0",
"codemirror": "^5.65.5",
"chokidar": "^3.5.2",
"constants-browserify": "^1.0.0",
"copy-webpack-plugin": "^10.2.0",
Expand Down
3 changes: 2 additions & 1 deletion plugin.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extraScripts": [
"driver/markdownItRuler/frontMatter/index.ts"
"driver/markdownItRuler/frontMatter/index.ts",
"driver/codemirror/frontmatter/index.ts"
]
}
21 changes: 19 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { string } from 'yargs';

export const IGNORE_FILES = 'ignoreFiles';
export const IMPORT_PATH = 'importPath';
export const EXTRACT_TAGS_FROM_FILE = 'extractTagsFromFile';
Expand All @@ -14,6 +12,8 @@ export const IMPORT_DUPLICATE_FILES = 'importDuplicateFiles';
export const SKIP_FILE_CONTENT = 'skipFileContent';
export const FRONT_MATTER_RENDER_RULE = 'frontMatterRenderRule';
export const FILE_HASH_ALGORITHM = 'fileHashAlgorithm';
export const CODEMIRROR_FRONT_MATTER = 'codemirrorFrontMatter';
export const FOLD_FRONT_MATTER = 'foldFrontMatter';

export class pluginSettings {
ignoreFiles: string;
Expand All @@ -31,4 +31,21 @@ export class pluginSettings {
skipFileContent: boolean;
frontMatterRenderRule: boolean;
fileHashAlgorithm: string;
codemirrorFrontMatter: boolean;
foldFrontMatter: boolean;
}

export enum ContextMsgType {
GET_SETTINGS,
OPEN_URL,
RESOURCE_PATH,
SHORTCUT
}
export class CodemirrorConfig {
public auto_fold_frontmatter: boolean;
public auto_fold_markdown: boolean;
}
export class ContextMsg {
type: ContextMsgType;
content: any;
}
9 changes: 7 additions & 2 deletions src/core/JoplinNotebook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
interface JoplinNotebook {
export interface iJoplinNotebook {
id: string;
title: string;
parent_id: string;
}

export class joplinNotebook implements iJoplinNotebook {
id: string;
title: string;
parent_id: string;
}
export { JoplinNotebook };
10 changes: 8 additions & 2 deletions src/core/archiveFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,25 @@ export class archiveFile implements iArchiveFile {

async archive(file: iRawFile): Promise<string> {
const archiveTarget = this._settings.Values.archiveTarget;
let result = '';
try {
console.log(`Archive file: ${file.Name} to: ${archiveTarget}.`);
const target = await this.createArchiveFolder(
archiveTarget,
file.Captured
);
const fileExt = path.extname(file.FullPath);
await this.archiveFile(file.FullPath, file.Name, target, fileExt);
result = await this.archiveFile(
file.FullPath,
file.Name,
target,
fileExt
);
} catch (e) {
console.error(e);
return undefined;
}
return '';
return result;
}

public async archiveFile(
Expand Down
50 changes: 50 additions & 0 deletions src/core/css-safe-string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* BEGIN HEADER
*
* Contains: Utility function
* CVM-Role: <none>
* Maintainer: Hendrik Erz
* License: GNU GPL v3
*
* Description: This function transforms an arbitrary string into a string
* that is safe to use in CSS class names. It is being used in
* the markdown-zkn mode as well as the clickable-yaml-tags
* plugin, both defined in the main editor.
*
* END HEADER
*/

/**
* Takes a string as input and sanitizes it for usage in a CSS class name or
* identifier. It may return an empty string in case the input does not contain
* any allowed characters.
*
* @param {string} unsaneText The string to sanitize for CSS
*
* @return {string} The sane string
*/
export default function cssSafeString(unsaneText: string): string {
// From the W3C (https://www.w3.org/TR/CSS21/syndata.html#characters):
//
// > In CSS, identifiers (including element names, classes, and IDs in
// > selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646
// > characters U+00A0 and higher, plus the hyphen (-) and the underscore (_);
// > they cannot start with a digit, two hyphens, or a hyphen followed by a
// > digit.
//
// To keep it simple, we only allow [a-zA-Z0-9], hyphens, and underscores.
return (
unsaneText
.toLowerCase()
// Spaces --> Hyphens
.replace(/\s/g, '-')
// Remove anything non-a-z0-9
.replace(/[^a-z0-9-_]/g, '')
// Replace a leading digit with underscore
.replace(/^\d/, '_')
// Replace two leading hyphens with underscores
.replace(/^--/, '__')
// Replace a leading hyphen-digit combo with underscores
.replace(/^-\d/, '__')
);
}
4 changes: 2 additions & 2 deletions src/core/defaultFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export class defaultFileHandler
extends typeHandlerBase
implements iDefaultFileHandler
{
private _name: string = 'defaultFileHandler';
private _name = 'defaultFileHandler';
private _supported: Array<string> = new Array<string>();

public IsDefault: boolean = true;
public IsDefault = true;

constructor(
@inject(TYPES.iAthenaConfiguration) settings: iAthenaConfiguration
Expand Down
2 changes: 1 addition & 1 deletion src/core/documentFrontMatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface documentFrontMatter {
Created: Date;
Modified: Date;
Captured: Date;
ResourceLing: string;
ResourceLink: string;
FileHash: iFileHash;
Metadata: Array<metaData>;
Content: string;
Expand Down
47 changes: 47 additions & 0 deletions src/core/generate-regex-for-highlight-mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* BEGIN HEADER
*
* Contains: Utility function
* CVM-Role: <none>
* Maintainer: Ville Kukkonen
* License: GNU GPL v3
*
* Description: Given an array of language selectors as strings, this function will
* generate a regex that matches fenced code block openings with given
* language selectors.
*
* END HEADER
*/

/**
* Given an array of language selectors as strings, this function will
* generate a regex that matches fenced code block openings with given
* language selectors.
*
* @param {string[]} selectors The language selectors to match against (e.g. js)
*
* @return {RegExp} The regex
*/
export default function generateRegexForHighlightMode(
selectors: string[]
): RegExp {
// The following regex will match fenced code block headers with or without attribute lists.
// Without attribute lists, the language selector is matched on the first word.
// In attribute lists, the language is matched on the first word prefixed with a dot (.).
return new RegExp(
// ``` or ~~~ preceded by zero or more whitespace
'^\\s*(?:`{3}|~{3})' +
// zero or more whitespace followed by either...
'\\s*(?:' +
// ... empty pattern, i.e. go directly to selectors ...
'|' +
// ... {. as a special case with no whitespace between the brace and dot...
'{\\.|' +
// ... { followed by anything up until first dot (.) preceded by whitespace.
'{[^\\.]*\\s\\.' +
// any of the given selectors
')(' +
selectors.join('|') +
')\\b.*$'
);
}
27 changes: 27 additions & 0 deletions src/core/iOldNoteFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface iOldNoteFormat {
Title: string;
Body: string;
Tags: Array<string>;
PDFMETADATATEXT: iOldPDFMetaData;
PDFCONTENTTEXT: string;
FILEHASHSTART: string;
Folder: string;
}

export interface iOldPDFMetaData {
Title: string;
Subject: string;
Author: string;
CreationDate: Date;
Keywords: string;
}

export class oldNoteFormat implements iOldNoteFormat {
Title: string;
Body: string;
Tags: string[];
PDFMETADATATEXT: iOldPDFMetaData;
PDFCONTENTTEXT: string;
FILEHASHSTART: string;
Folder: string;
}
Loading

0 comments on commit e1ad694

Please sign in to comment.