@@ -13,17 +13,19 @@ function imageUri(searchUri: vscode.Uri, imageLink: string) {
1313 if ( imageLink . match ( / ^ ( h t ) | ( f ) t p s ? : \/ \/ / ) ) {
1414 imageUri = vscode . Uri . parse ( imageLink ) ;
1515 } else {
16- let extPath = path . dirname ( searchUri . fsPath ) ;
17- imageUri = vscode . Uri . file ( path . join ( extPath , imageLink ) ) ;
16+ imageUri = vscode . Uri . file ( path . join ( searchUri . fsPath , imageLink ) ) . with ( { scheme : 'vscode-resource' } ) ;
1817 }
1918 return imageUri ;
2019}
2120
22- function getUri ( filepath : string , filename : string ) {
21+ function getUri ( filepath : string , filename : string ) {
2322 let extension = vscode . extensions . getExtension ( EXTENTION_ID ) ;
2423 if ( extension ) {
2524 let extPath = extension . extensionPath ;
26- let uri = vscode . Uri . file ( path . join ( extPath , filepath , filename ) ) ;
25+
26+ // set special chema for resource:
27+ // https://code.visualstudio.com/api/extension-guides/webview#loading-local-content
28+ let uri = vscode . Uri . file ( path . join ( extPath , filepath , filename ) ) . with ( { scheme : 'vscode-resource' } ) ;
2729 return uri ;
2830 }
2931}
@@ -36,7 +38,7 @@ export function cssUri(cssFile: string) {
3638 return getUri ( CSS_PATH , cssFile ) ;
3739}
3840
39- export async function parseMarkup ( sourceUri : vscode . Uri , sourceText : string ) {
41+ export function parseMarkup ( sourceUri : vscode . Uri , sourceText : string ) {
4042 //TODO: use Tokenazer instead of line loop
4143
4244 var result = '' ;
@@ -92,7 +94,7 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
9294 html_tag = true ;
9395 }
9496 //img
95- let img = / ! ( . * ) ! / ;
97+ let img = / ! ( [ ^ | ] * ) \| ? . * ! / ;
9698 let match = tag . match ( img ) ;
9799 if ( match ) {
98100 tag = '<img src="' + imageUri ( sourceUri , match [ 1 ] ) + '"/>' ;
@@ -109,7 +111,7 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
109111 tag = tag . replace ( / ^ \| / , '<td>' ) ;
110112 tag = tag . replace ( / \| $ / , '</td>' ) ;
111113 tag = tag . replace ( / \| / gi, '</td><td>' ) ;
112- if ( tableFlag == false ) {
114+ if ( tableFlag == false ) {
113115 tag = '<table>' + tag ;
114116 }
115117 tag = '<tr>' + tag + '</tr>' ;
@@ -147,7 +149,7 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
147149 listTag = 'ol' ;
148150 // reset ol after 3rd level
149151 // add count of non-ol elements for mixed lists
150- if ( ( match [ 1 ] . length + ( match [ 1 ] . match ( / [ - | \* ] / g) || [ ] ) . length ) % 3 === 1 ) {
152+ if ( ( match [ 1 ] . length + ( match [ 1 ] . match ( / [ - | \* ] / g) || [ ] ) . length ) % 3 === 1 ) {
151153 listStyle = ' class="initial"' ;
152154 }
153155 }
@@ -158,11 +160,11 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
158160 listStyle = ' class="alternate"' ;
159161 }
160162 if ( match [ 1 ] . length > listArr . length ) {
161- tag = '<' + listTag + listStyle + '>' ;
163+ tag = '<' + listTag + listStyle + '>' ;
162164 listArr . push ( listTag ) ;
163165 }
164166 if ( match [ 1 ] . length < listArr . length ) {
165- tag = '</' + listArr . slice ( match [ 1 ] . length , listArr . length ) . reverse ( ) . join ( '></' ) + '>' ;
167+ tag = '</' + listArr . slice ( match [ 1 ] . length , listArr . length ) . reverse ( ) . join ( '></' ) + '>' ;
166168 listArr = listArr . slice ( 0 , match [ 1 ] . length ) ;
167169 }
168170 tag += "<li>" + match [ 2 ] + "</li>" ;
@@ -188,12 +190,12 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
188190 tag = tag . replace ( / _ ( [ \w ] * ) _ / g, "<i>$1</i>" ) ;
189191 }
190192 } else {
191- if ( tag !== '<pre><code>' ) {
193+ if ( tag !== '<pre><code>' ) {
192194 tag = tag . replace ( / < / gi, '<' ) + '<br />' ;
193195 }
194196 }
195197
196- if ( tag . match ( / ^ s * $ / ) ) {
198+ if ( tag . match ( / ^ s * $ / ) ) {
197199 tag = '<br />' ;
198200 }
199201
0 commit comments