Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shared-types.d.ts 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. // Minimum TypeScript Version: 3.0
  2. import {Code} from './character/codes'
  3. import {Type} from './constant/types'
  4. /**
  5. * A location in a string or buffer
  6. */
  7. export interface Point {
  8. line: number
  9. column: number
  10. offset: number
  11. _index?: number
  12. _bufferIndex?: number
  13. }
  14. /**
  15. *
  16. */
  17. export interface Token {
  18. type: Type
  19. start: Point
  20. end: Point
  21. previous?: Token
  22. next?: Token
  23. /**
  24. * Declares a token as having content of a certain type.
  25. * Because markdown requires to first parse containers, flow, content completely,
  26. * and then later go on to phrasing and such, it needs to be declared somewhere on the tokens.
  27. */
  28. contentType?: 'flow' | 'content' | 'string' | 'text'
  29. /**
  30. * Used when dealing with linked tokens. A child tokenizer is needed to tokenize them, which is stored on those tokens
  31. */
  32. _tokenizer?: Tokenizer
  33. /**
  34. * Close and open are also used in attention:
  35. * depending on the characters before and after sequences (**),
  36. * the sequence can open, close, both, or none
  37. */
  38. _open?: boolean
  39. /**
  40. * Close and open are also used in attention:
  41. * depending on the characters before and after sequences (**),
  42. * the sequence can open, close, both, or none
  43. */
  44. _close?: boolean
  45. }
  46. /**
  47. *
  48. */
  49. export type Event = [string, Token, Tokenizer]
  50. /**
  51. * These these are transitions to update the CommonMark State Machine (CSMS)
  52. */
  53. export interface Effects {
  54. /**
  55. * Enter and exit define where tokens start and end
  56. */
  57. enter: (type: Type) => Token
  58. /**
  59. * Enter and exit define where tokens start and end
  60. */
  61. exit: (type: Type) => Token
  62. /**
  63. * Consume deals with a character, and moves to the next
  64. */
  65. consume: (code: number) => void
  66. /**
  67. * Attempt deals with several values, and tries to parse according to those values.
  68. * If a value resulted in `ok`, it worked, the tokens that were made are used,
  69. * and `returnState` is switched to.
  70. * If the result is `nok`, the attempt failed,
  71. * so we revert to the original state, and `bogusState` is used.
  72. */
  73. attempt: (
  74. constructInfo:
  75. | Construct
  76. | Construct[]
  77. | Record<CodeAsKey, Construct | Construct[]>,
  78. returnState: State,
  79. bogusState?: State
  80. ) => (code: Code) => void
  81. /**
  82. * Interrupt is used for stuff right after a line of content.
  83. */
  84. interrupt: (
  85. constructInfo:
  86. | Construct
  87. | Construct[]
  88. | Record<CodeAsKey, Construct | Construct[]>,
  89. ok: Okay,
  90. nok?: NotOkay
  91. ) => (code: Code) => void
  92. check: (
  93. constructInfo:
  94. | Construct
  95. | Construct[]
  96. | Record<CodeAsKey, Construct | Construct[]>,
  97. ok: Okay,
  98. nok?: NotOkay
  99. ) => (code: Code) => void
  100. /**
  101. * Lazy is used for lines that were not properly preceded by the container.
  102. */
  103. lazy: (
  104. constructInfo:
  105. | Construct
  106. | Construct[]
  107. | Record<CodeAsKey, Construct | Construct[]>,
  108. ok: Okay,
  109. nok?: NotOkay
  110. ) => void
  111. }
  112. /**
  113. * A state function should return another function: the next state-as-a-function to go to.
  114. *
  115. * But there is one case where they return void: for the eof character code (at the end of a value)
  116. * The reason being: well, there isn’t any state that makes sense, so void works well. Practically
  117. * that has also helped: if for some reason it was a mistake, then an exception is throw because
  118. * there is no next function, meaning it surfaces early.
  119. */
  120. export type State = (code: number) => State | void
  121. /**
  122. *
  123. */
  124. export type Okay = State
  125. /**
  126. *
  127. */
  128. export type NotOkay = State
  129. /**
  130. *
  131. */
  132. export interface Tokenizer {
  133. previous: Code
  134. events: Event[]
  135. parser: Parser
  136. sliceStream: (token: Token) => Chunk[]
  137. sliceSerialize: (token: Token) => string
  138. now: () => Point
  139. defineSkip: (value: Point) => void
  140. write: (slice: Chunk[]) => Event[]
  141. }
  142. export type Resolve = (events: Event[], context: Tokenizer) => Event[]
  143. export type Tokenize = (context: Tokenizer, effects: Effects) => State
  144. export interface Construct {
  145. name?: string
  146. tokenize: Tokenize
  147. partial?: boolean
  148. resolve?: Resolve
  149. resolveTo?: Resolve
  150. resolveAll?: Resolve
  151. concrete?: boolean
  152. interruptible?: boolean
  153. lazy?: boolean
  154. }
  155. /**
  156. *
  157. */
  158. export interface Parser {
  159. constructs: Record<CodeAsKey, Construct | Construct[]>
  160. content: (from: Point) => Tokenizer
  161. document: (from: Point) => Tokenizer
  162. flow: (from: Point) => Tokenizer
  163. string: (from: Point) => Tokenizer
  164. text: (from: Point) => Tokenizer
  165. defined: string[]
  166. }
  167. /**
  168. *
  169. */
  170. export interface TokenizerThis {
  171. events: Event[]
  172. interrupt?: boolean
  173. lazy?: boolean
  174. containerState?: Record<string, unknown>
  175. }
  176. /**
  177. * `Compile` is the return value of `lib/compile/html.js`
  178. */
  179. export type Compile = (slice: Event[]) => string
  180. /**
  181. * https://github.com/micromark/micromark#syntaxextension
  182. */
  183. export interface SyntaxExtension {
  184. document?: Record<CodeAsKey, Construct | Construct[]>
  185. contentInitial?: Record<CodeAsKey, Construct | Construct[]>
  186. flowInitial?: Record<CodeAsKey, Construct | Construct[]>
  187. flow?: Record<CodeAsKey, Construct | Construct[]>
  188. string?: Record<CodeAsKey, Construct | Construct[]>
  189. text?: Record<CodeAsKey, Construct | Construct[]>
  190. }
  191. /**
  192. * https://github.com/micromark/micromark#htmlextension
  193. */
  194. export type HtmlExtension =
  195. | {enter: Record<Type, () => void>}
  196. | {exit: Record<Type, () => void>}
  197. export type Options = ParseOptions & CompileOptions
  198. export interface ParseOptions {
  199. // Array of syntax extensions
  200. //
  201. extensions?: SyntaxExtension[]
  202. }
  203. export interface CompileOptions {
  204. // Value to use for line endings not in `doc` (`string`, default: first line
  205. // ending or `'\n'`).
  206. //
  207. // Generally, micromark copies line endings (`'\r'`, `'\n'`, `'\r\n'`) in the
  208. // markdown document over to the compiled HTML.
  209. // In some cases, such as `> a`, CommonMark requires that extra line endings are
  210. // added: `<blockquote>\n<p>a</p>\n</blockquote>`.
  211. //
  212. defaultLineEnding?: '\r' | '\n' | '\r\n'
  213. // Whether to allow embedded HTML (`boolean`, default: `false`).
  214. //
  215. allowDangerousHtml?: boolean
  216. // Whether to allow potentially dangerous protocols in links and images (`boolean`,
  217. // default: `false`).
  218. // URLs relative to the current protocol are always allowed (such as, `image.jpg`).
  219. // For links, the allowed protocols are `http`, `https`, `irc`, `ircs`, `mailto`,
  220. // and `xmpp`.
  221. // For images, the allowed protocols are `http` and `https`.
  222. //
  223. allowDangerousProtocol?: boolean
  224. // Array of HTML extensions
  225. //
  226. htmlExtensions?: HtmlExtension[]
  227. }
  228. export type Chunk = NonNullable<Code> | string
  229. // TypeScript will complain that `null` can't be the key of an object. So when a `Code` value is a key of an object, use CodeAsKey instead.
  230. export type CodeAsKey = NonNullable<Code> | 'null'
  231. /**
  232. * Encodings supported by the buffer class
  233. *
  234. * @remarks
  235. * This is a copy of the typing from Node, copied to prevent Node globals from being needed.
  236. * Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a2bc1d868d81733a8969236655fa600bd3651a7b/types/node/globals.d.ts#L174
  237. */
  238. export type BufferEncoding =
  239. | 'ascii'
  240. | 'utf8'
  241. | 'utf-8'
  242. | 'utf16le'
  243. | 'ucs2'
  244. | 'ucs-2'
  245. | 'base64'
  246. | 'latin1'
  247. | 'binary'
  248. | 'hex'
  249. /**
  250. * This is an interface for Node's Buffer.
  251. */
  252. export interface Buffer {
  253. toString: (encoding?: BufferEncoding) => string
  254. }
  255. export type CodeCheck = (code: Code) => boolean