mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
fix: code style
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
fa5b9c7beb
commit
c775db9a2e
3 changed files with 25 additions and 16 deletions
|
@ -38,7 +38,7 @@ export function convertInlineStyleToMap(
|
||||||
const replacedProperty = property
|
const replacedProperty = property
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/^-ms-/, 'ms-')
|
.replace(/^-ms-/, 'ms-')
|
||||||
.replace(/-(.)/g, (_, character) => character.toUpperCase())
|
.replace(/-(.)/g, (_, character: string) => character.toUpperCase())
|
||||||
|
|
||||||
// add the new style property and value to the style object
|
// add the new style property and value to the style object
|
||||||
styleObject[replacedProperty] = value
|
styleObject[replacedProperty] = value
|
||||||
|
|
|
@ -12,8 +12,8 @@ import { SpecialCharacters } from './specialCharacters.js'
|
||||||
|
|
||||||
const checkForImageTagStart = (state: StateInline): boolean => {
|
const checkForImageTagStart = (state: StateInline): boolean => {
|
||||||
return (
|
return (
|
||||||
state.src.charCodeAt(state.pos) === SpecialCharacters.EXCLAMATION_MARK &&
|
state.src.charCodeAt(state.pos) === (SpecialCharacters.EXCLAMATION_MARK as number) &&
|
||||||
state.src.charCodeAt(state.pos + 1) === SpecialCharacters.OPENING_BRACKET
|
state.src.charCodeAt(state.pos + 1) === (SpecialCharacters.OPENING_BRACKET as number)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ const skipWhiteSpaces = (startPosition: number, state: StateInline): number => {
|
||||||
let position = startPosition
|
let position = startPosition
|
||||||
while (position < state.posMax) {
|
while (position < state.posMax) {
|
||||||
const code = state.src.charCodeAt(position)
|
const code = state.src.charCodeAt(position)
|
||||||
if (code !== SpecialCharacters.WHITESPACE && code !== SpecialCharacters.NEW_LINE) {
|
if (code !== (SpecialCharacters.WHITESPACE as number) && code !== (SpecialCharacters.NEW_LINE as number)) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
position += 1
|
position += 1
|
||||||
|
@ -68,6 +68,15 @@ function createImageToken(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface LinkReference {
|
||||||
|
href: string
|
||||||
|
title: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ReferenceEnvironment {
|
||||||
|
references?: Record<string, LinkReference>
|
||||||
|
}
|
||||||
|
|
||||||
function parseSizeParameters(startPosition: number, state: StateInline): ParseImageSize | undefined {
|
function parseSizeParameters(startPosition: number, state: StateInline): ParseImageSize | undefined {
|
||||||
// [link]( <href> "title" =WxH )
|
// [link]( <href> "title" =WxH )
|
||||||
// ^^^^ parsing image size
|
// ^^^^ parsing image size
|
||||||
|
@ -75,7 +84,7 @@ function parseSizeParameters(startPosition: number, state: StateInline): ParseIm
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const code = state.src.charCodeAt(startPosition - 1)
|
const code = state.src.charCodeAt(startPosition - 1)
|
||||||
if (code !== SpecialCharacters.WHITESPACE) {
|
if (code !== (SpecialCharacters.WHITESPACE as number)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const res = parseImageSize(state.src, startPosition, state.posMax)
|
const res = parseImageSize(state.src, startPosition, state.posMax)
|
||||||
|
@ -135,7 +144,7 @@ const imageWithSize: ParserInline.RuleInline = (state, silent) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
position = labelEndIndex + 1
|
position = labelEndIndex + 1
|
||||||
if (position < max && state.src.charCodeAt(position) === SpecialCharacters.OPENING_PARENTHESIS) {
|
if (position < max && state.src.charCodeAt(position) === (SpecialCharacters.OPENING_PARENTHESIS as number)) {
|
||||||
//
|
//
|
||||||
// Inline link
|
// Inline link
|
||||||
//
|
//
|
||||||
|
@ -181,7 +190,7 @@ const imageWithSize: ParserInline.RuleInline = (state, silent) => {
|
||||||
height = parseSizeParametersResult.height
|
height = parseSizeParametersResult.height
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position >= max || state.src.charCodeAt(position) !== SpecialCharacters.CLOSING_PARENTHESIS) {
|
if (position >= max || state.src.charCodeAt(position) !== (SpecialCharacters.CLOSING_PARENTHESIS as number)) {
|
||||||
state.pos = oldPos
|
state.pos = oldPos
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -190,7 +199,7 @@ const imageWithSize: ParserInline.RuleInline = (state, silent) => {
|
||||||
//
|
//
|
||||||
// Link reference
|
// Link reference
|
||||||
//
|
//
|
||||||
if (typeof state.env.references === 'undefined') {
|
if (typeof (state.env as ReferenceEnvironment).references === 'undefined') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +209,7 @@ const imageWithSize: ParserInline.RuleInline = (state, silent) => {
|
||||||
|
|
||||||
let label
|
let label
|
||||||
|
|
||||||
if (position < max && state.src.charCodeAt(position) === SpecialCharacters.OPENING_BRACKET) {
|
if (position < max && state.src.charCodeAt(position) === (SpecialCharacters.OPENING_BRACKET as number)) {
|
||||||
start = position + 1
|
start = position + 1
|
||||||
position = state.md.helpers.parseLinkLabel(state, position)
|
position = state.md.helpers.parseLinkLabel(state, position)
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
|
@ -218,7 +227,7 @@ const imageWithSize: ParserInline.RuleInline = (state, silent) => {
|
||||||
label = state.src.slice(labelStartIndex, labelEndIndex)
|
label = state.src.slice(labelStartIndex, labelEndIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
const ref = state.env.references[state.md.utils.normalizeReference(label)]
|
const ref = (state.env as ReferenceEnvironment).references?.[state.md.utils.normalizeReference(label)]
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
state.pos = oldPos
|
state.pos = oldPos
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -18,13 +18,13 @@ export interface ParseNextNumber {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCharacterADigit(code: number) {
|
function isCharacterADigit(code: number) {
|
||||||
return code >= SpecialCharacters.NUMBER_ZERO && code <= SpecialCharacters.NUMBER_NINE
|
return code >= (SpecialCharacters.NUMBER_ZERO as number) && code <= (SpecialCharacters.NUMBER_NINE as number)
|
||||||
}
|
}
|
||||||
|
|
||||||
function findNextNotNumberCharacter(startPosition: number, maximalPosition: number, content: string): number {
|
function findNextNotNumberCharacter(startPosition: number, maximalPosition: number, content: string): number {
|
||||||
for (let position = startPosition; position < maximalPosition; position += 1) {
|
for (let position = startPosition; position < maximalPosition; position += 1) {
|
||||||
const code = content.charCodeAt(position)
|
const code = content.charCodeAt(position)
|
||||||
if (!isCharacterADigit(code) && code !== SpecialCharacters.PERCENTAGE) {
|
if (!isCharacterADigit(code) && code !== (SpecialCharacters.PERCENTAGE as number)) {
|
||||||
return position
|
return position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ function parseNextNumber(content: string, startPosition: number, maximalPosition
|
||||||
*/
|
*/
|
||||||
const checkImageSizeStart = (code: number): boolean => {
|
const checkImageSizeStart = (code: number): boolean => {
|
||||||
return (
|
return (
|
||||||
code === SpecialCharacters.LOWER_CASE_X ||
|
code === (SpecialCharacters.LOWER_CASE_X as number) ||
|
||||||
(code >= SpecialCharacters.NUMBER_ZERO && code <= SpecialCharacters.NUMBER_NINE)
|
(code >= (SpecialCharacters.NUMBER_ZERO as number) && code <= (SpecialCharacters.NUMBER_NINE as number))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ export function parseImageSize(
|
||||||
|
|
||||||
let currentCharacterPosition = startCharacterPosition
|
let currentCharacterPosition = startCharacterPosition
|
||||||
|
|
||||||
if (imageSize.charCodeAt(currentCharacterPosition) !== SpecialCharacters.EQUALS /* = */) {
|
if (imageSize.charCodeAt(currentCharacterPosition) !== (SpecialCharacters.EQUALS as number)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ export function parseImageSize(
|
||||||
|
|
||||||
// next charactor must be 'x'
|
// next charactor must be 'x'
|
||||||
const code = imageSize.charCodeAt(currentCharacterPosition)
|
const code = imageSize.charCodeAt(currentCharacterPosition)
|
||||||
if (code !== SpecialCharacters.LOWER_CASE_X /* x */) {
|
if (code !== (SpecialCharacters.LOWER_CASE_X as number)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentCharacterPosition += 1
|
currentCharacterPosition += 1
|
||||||
|
|
Loading…
Reference in a new issue