-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts and functionality to import DM1 TTL files and images (#229)
- Loading branch information
1 parent
6525bf2
commit 49559a6
Showing
12 changed files
with
420 additions
and
53 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
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,55 @@ | ||
|
||
// Add new CSS styles here | ||
const supportedTextStyles = { | ||
color: { cssKey: "color", default: "#000" }, | ||
fontSize: { cssKey: "font-size", default: "normal" }, | ||
textDecoration: { cssKey: "text-decoration", default: "none" } | ||
} | ||
|
||
// The textStyle ProseMirror MarkSpec | ||
export const textStyle = { | ||
attrs: textStyleMarkAttributes(), | ||
parseDOM: [{tag: "span", getAttrs(dom) { | ||
return cssToMarkAttr( dom.getAttribute("style") ) | ||
}}], | ||
toDOM(mark) { | ||
return ["span", { style: markAttrsToCSS( mark.attrs ) }, 0] | ||
} | ||
} | ||
|
||
function textStyleMarkAttributes() { | ||
let markAttrs = {} | ||
for( let styleKey of Object.keys(supportedTextStyles) ) { | ||
const defaultValue = supportedTextStyles[styleKey].default | ||
markAttrs[styleKey] = { default: defaultValue } | ||
} | ||
return markAttrs | ||
} | ||
|
||
function cssToMarkAttr( styleAttribute ) { | ||
if( !styleAttribute ) return null | ||
let foundStyles = {} | ||
for( let styleKey of Object.keys(supportedTextStyles) ) { | ||
const cssKey = supportedTextStyles[styleKey].cssKey | ||
const styleRegEx = new RegExp(`${cssKey}:\\s*([^;]*)`) | ||
let matches = styleAttribute.match(styleRegEx) | ||
let value = matches && matches.length > 1 ? matches[1] : null; | ||
if( value ) { | ||
foundStyles[styleKey] = value | ||
} | ||
} | ||
return foundStyles | ||
} | ||
|
||
function markAttrsToCSS( attrs ) { | ||
let styleStr = "" | ||
for( let styleKey of Object.keys(supportedTextStyles) ) { | ||
const cssKey = supportedTextStyles[styleKey].cssKey | ||
const value = attrs[styleKey] | ||
if( value ) { | ||
styleStr = styleStr.concat(`${cssKey}:${value};`) | ||
} | ||
} | ||
return styleStr | ||
} | ||
|
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
Oops, something went wrong.