@@ -8,6 +8,7 @@ let allowedElements, requiredAttributes, transformElements, blockLevelElements
88let splitIntoBlocks , blacklistedElements
99let whitespaceOnly = / ^ \s * $ /
1010let blockPlaceholder = '<!-- BLOCK -->'
11+ let keepInternalRelativeLinks
1112
1213updateConfig ( config )
1314export function updateConfig ( config ) {
@@ -16,6 +17,7 @@ export function updateConfig (config) {
1617 requiredAttributes = rules . requiredAttributes || { }
1718 transformElements = rules . transformElements || { }
1819 blacklistedElements = rules . blacklistedElements || [ ]
20+ keepInternalRelativeLinks = rules . keepInternalRelativeLinks || false
1921
2022 blockLevelElements = { }
2123 rules . blockLevelElements . forEach ( ( name ) => { blockLevelElements [ name ] = true } )
@@ -41,7 +43,6 @@ export function paste (element, cursor, callback) {
4143 const blocks = parseContent ( pasteHolder )
4244 $ ( pasteHolder ) . remove ( )
4345 element . removeAttribute ( config . pastingAttribute )
44-
4546 cursor . restore ( )
4647 callback ( blocks , cursor )
4748 } , 0 )
@@ -68,6 +69,8 @@ export function injectPasteholder (document) {
6869 * - Parse pasted content
6970 * - Split it up into blocks
7071 * - clean and normalize every block
72+ * - optionally strip the host location an anchorTag-href
73+ * www.livindocs.io/internalLink -> /internalLink
7174 *
7275 * @param {DOM node } A container where the pasted content is located.
7376 * @returns {Array of Strings } An array of cleaned innerHTML like strings.
@@ -87,14 +90,19 @@ export function filterHtmlElements (elem) {
8790 return ''
8891 }
8992
93+ // Keep internal relative links relative (on paste).
94+ if ( keepInternalRelativeLinks && child . nodeName === 'A' && child . href ) {
95+ const stripInternalHost = child . href . replace ( window . location . origin , '' )
96+ child . setAttribute ( 'href' , stripInternalHost )
97+ }
98+
9099 if ( child . nodeType === nodeType . elementNode ) {
91100 const childContent = filterHtmlElements ( child )
92101 return content + conditionalNodeWrap ( child , childContent )
93102 }
94103
95104 // Escape HTML characters <, > and &
96105 if ( child . nodeType === nodeType . textNode ) return content + string . escapeHtml ( child . nodeValue )
97-
98106 return content
99107 } , '' )
100108}
0 commit comments