-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74bedef
commit 913bae0
Showing
21 changed files
with
5,704 additions
and
3,555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"es2015", | ||
"env", | ||
{ | ||
"modules": false | ||
} | ||
] | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import MarkdownIt from "markdown-it"; | ||
export interface CheckboxPluginOptions { | ||
divWrap: boolean; | ||
divClass: string; | ||
idPrefix: string; | ||
readonly: boolean; | ||
checkboxClass: string; | ||
} | ||
export declare function CheckBoxReplacer(md: MarkdownIt, userOptions: Partial<CheckboxPluginOptions>): MarkdownIt.Rule; | ||
export declare function CheckboxPlugin(md: MarkdownIt, options: CheckboxPluginOptions): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,121 @@ | ||
// based on https://github.com/mcecot/markdown-it-checkbox | ||
|
||
import * as MarkdownIt from "markdown-it"; | ||
import {Token} from "markdown-it"; | ||
import MarkdownIt from "markdown-it"; | ||
import Token from 'markdown-it/lib/token'; | ||
import StateCore from "markdown-it/lib/rules_core/state_core"; | ||
|
||
export interface CheckboxPluginOptions { | ||
divWrap: boolean; | ||
divClass: string; | ||
idPrefix: string; | ||
readonly: boolean; | ||
checkboxClass: string; | ||
divWrap: boolean; | ||
divClass: string; | ||
idPrefix: string; | ||
readonly: boolean; | ||
checkboxClass: string; | ||
} | ||
|
||
interface TokenConstructor { | ||
new (name: string, tagName: string, someNumber: number): Token; | ||
new(name: string, tagName: string, someNumber: number): Token; | ||
} | ||
|
||
interface CheckboxReplacerState { | ||
tokens: Token[]; | ||
Token: TokenConstructor; | ||
interface CheckboxReplacerState extends StateCore { | ||
Token: TokenConstructor; | ||
} | ||
|
||
export function CheckBoxReplacer(md: MarkdownIt.MarkdownIt, userOptions: Partial<CheckboxPluginOptions>): MarkdownIt.Rule { | ||
let lastId = 0; | ||
const defaults: CheckboxPluginOptions = { | ||
divWrap: false, | ||
divClass: 'checkbox', | ||
idPrefix: 'checkbox', | ||
readonly: true, | ||
checkboxClass: '' | ||
}; | ||
const options = $.extend(defaults, userOptions); | ||
const pattern = /\[(X|\s|\_|\-)\]\s(.*)/i; | ||
const createTokens = function (checked: boolean, label: string, Token: TokenConstructor, line: number): Token[] { | ||
const nodes: Token[] = []; | ||
let token: Token; | ||
export function CheckBoxReplacer(md: MarkdownIt, userOptions: Partial<CheckboxPluginOptions>): MarkdownIt.Rule { | ||
let lastId = 0; | ||
const defaults: CheckboxPluginOptions = { | ||
divWrap: false, | ||
divClass: 'checkbox', | ||
idPrefix: 'checkbox', | ||
readonly: true, | ||
checkboxClass: '' | ||
}; | ||
const options = $.extend(defaults, userOptions); | ||
const pattern = /\[(X|\s|\_|\-)\]\s(.*)/i; | ||
const createTokens = function (checked: boolean, label: string, Token: TokenConstructor, line: number): Token[] { | ||
const nodes: Token[] = []; | ||
let token: Token; | ||
|
||
/** | ||
* <div class="checkbox"> | ||
*/ | ||
if (options.divWrap) { | ||
token = new Token("checkbox_open", "div", 1); | ||
token.attrs = [["class", options.divClass]]; | ||
nodes.push(token); | ||
} | ||
/** | ||
* <div class="checkbox"> | ||
*/ | ||
if (options.divWrap) { | ||
token = new Token("checkbox_open", "div", 1); | ||
token.attrs = [["class", options.divClass]]; | ||
nodes.push(token); | ||
} | ||
|
||
/** | ||
* <input type="checkbox" id="checkbox{n}" checked="true data-line="{n}"> | ||
*/ | ||
const id = options.idPrefix + lastId; | ||
lastId += 1; | ||
token = new Token("checkbox_input", "input", 0); | ||
token.attrs = [["type", "checkbox"], ["id", id]]; | ||
if (checked === true) { | ||
token.attrs.push(["checked", "true"]); | ||
} | ||
if (options.readonly) { | ||
token.attrs.push(["disabled", "disabled"]); | ||
} | ||
if (options.checkboxClass) { | ||
token.attrs.push(["class", options.checkboxClass]); | ||
} | ||
token.attrs.push(["data-line", String(line)]); | ||
nodes.push(token); | ||
/** | ||
* <input type="checkbox" id="checkbox{n}" checked="true data-line="{n}"> | ||
*/ | ||
const id = options.idPrefix + lastId; | ||
lastId += 1; | ||
token = new Token("checkbox_input", "input", 0); | ||
token.attrs = [["type", "checkbox"], ["id", id]]; | ||
if (checked === true) { | ||
token.attrs.push(["checked", "true"]); | ||
} | ||
if (options.readonly) { | ||
token.attrs.push(["disabled", "disabled"]); | ||
} | ||
if (options.checkboxClass) { | ||
token.attrs.push(["class", options.checkboxClass]); | ||
} | ||
token.attrs.push(["data-line", String(line)]); | ||
nodes.push(token); | ||
|
||
/** | ||
* <label for="checkbox{n}"> | ||
*/ | ||
token = new Token("label_open", "label", 1); | ||
token.attrs = [["for", id]]; | ||
nodes.push(token); | ||
/** | ||
* <label for="checkbox{n}"> | ||
*/ | ||
token = new Token("label_open", "label", 1); | ||
token.attrs = [["for", id]]; | ||
nodes.push(token); | ||
|
||
/** | ||
* content of label tag | ||
*/ | ||
token = new Token("text", "", 0); | ||
token.content = label; | ||
nodes.push(token); | ||
/** | ||
* content of label tag | ||
*/ | ||
token = new Token("text", "", 0); | ||
token.content = label; | ||
nodes.push(token); | ||
|
||
/** | ||
* closing tags | ||
*/ | ||
nodes.push(new Token("label_close", "label", -1)); | ||
if (options.divWrap) { | ||
nodes.push(new Token("checkbox_close", "div", -1)); | ||
} | ||
return nodes; | ||
}; | ||
/** | ||
* closing tags | ||
*/ | ||
nodes.push(new Token("label_close", "label", -1)); | ||
if (options.divWrap) { | ||
nodes.push(new Token("checkbox_close", "div", -1)); | ||
} | ||
return nodes; | ||
}; | ||
|
||
const splitTextToken = function (original: Token, Token: TokenConstructor, line: number): Token[] { | ||
const text = original.content; | ||
const matches = text.match(pattern); | ||
if (matches === null) { | ||
return [original]; | ||
} | ||
const value = matches[1]; | ||
const label = matches[2]; | ||
const checked = (value === "X" || value === "x"); | ||
return createTokens(checked, label, Token, line); | ||
}; | ||
const splitTextToken = function (original: Token, Token: TokenConstructor, line: number): Token[] { | ||
const text = original.content; | ||
const matches = text.match(pattern); | ||
if (matches === null) { | ||
return [original]; | ||
} | ||
const value = matches[1]; | ||
const label = matches[2]; | ||
const checked = (value === "X" || value === "x"); | ||
return createTokens(checked, label, Token, line); | ||
}; | ||
|
||
return function (state: CheckboxReplacerState) { | ||
for (const token of state.tokens) { | ||
if (token.type === "inline") { | ||
let currentLine = token.map ? token.map[0] : 0; | ||
let newChildren: Token[] = []; | ||
for (const childToken of token.children) { | ||
if (childToken.type === 'hardbreak' || childToken.type === 'softbreak') { | ||
currentLine++; | ||
} | ||
newChildren = newChildren.concat(splitTextToken(childToken, state.Token, currentLine)) | ||
} | ||
token.children = newChildren; | ||
} | ||
} | ||
}; | ||
return function (state: CheckboxReplacerState) { | ||
for (const token of state.tokens) { | ||
if (token.type === "inline") { | ||
let currentLine = token.map ? token.map[0] : 0; | ||
let newChildren: Token[] = []; | ||
for (const childToken of token.children) { | ||
if (childToken.type === 'hardbreak' || childToken.type === 'softbreak') { | ||
currentLine++; | ||
} | ||
newChildren = newChildren.concat(splitTextToken(childToken, state.Token, currentLine)) | ||
} | ||
token.children = newChildren; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
export function CheckboxPlugin(md: MarkdownIt.MarkdownIt, options: CheckboxPluginOptions) { | ||
md.core.ruler.push("checkbox", CheckBoxReplacer(md, options)); | ||
export function CheckboxPlugin(md: MarkdownIt, options: CheckboxPluginOptions) { | ||
md.core.ruler.push("checkbox", CheckBoxReplacer(md, options)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import MarkdownIt from "markdown-it"; | ||
export declare const MermaidPlugin: (md: MarkdownIt) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export declare type PasteListener = (image: HTMLImageElement, file: File) => void; | ||
export declare class PasteImage { | ||
private initialized; | ||
private listeners; | ||
private listenForPaste; | ||
private init; | ||
private pasteHandler; | ||
private getURLObj; | ||
private createImage; | ||
listen(handler: PasteListener): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/// <reference types="underscore" /> | ||
import Thenable = JQuery.Thenable; | ||
import TextEditorPreviewPlugin = OCA.Files_Texteditor.TextEditorPreviewPlugin; | ||
export declare class PreviewPlugin implements TextEditorPreviewPlugin { | ||
private renderer; | ||
private rangeConstructor; | ||
private initPromise; | ||
private textEditorOnHashChange; | ||
private offsetMap; | ||
private session; | ||
private previewElement; | ||
private scrollMode; | ||
init(): Promise<void>; | ||
initAceHooks(): void; | ||
initPreviewHooks(element: any): void; | ||
onHashChange(e: PopStateEvent): void; | ||
preview: ((text: string, element: any) => void) & import("underscore").Cancelable; | ||
initCheckboxHandler(element: any): void; | ||
buildOffsetMap: ((element: any) => void) & import("underscore").Cancelable; | ||
onScrollEditor: ((top: number) => void) & import("underscore").Cancelable; | ||
onScrollPreview: (() => void) & import("underscore").Cancelable; | ||
resetScrollMode: (() => void) & import("underscore").Cancelable; | ||
handleImage: (image: HTMLImageElement, file: any) => void; | ||
uploadImage(name: string, file: File): Thenable<void>; | ||
getCurrentPath(): string | undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export declare class PublicPreview { | ||
private renderer; | ||
private initPromise; | ||
init(): JQueryPromise<void>; | ||
attach(previewElement: JQuery, shareToken: string): void; | ||
getFileContent(shareToken: string): JQuery.jqXHR<any>; | ||
} |
Oops, something went wrong.