Skip to content

Commit

Permalink
feat: figure parsing in reoff
Browse files Browse the repository at this point in the history
  • Loading branch information
tefkah committed Feb 16, 2022
1 parent e4662b5 commit fe2b9f8
Show file tree
Hide file tree
Showing 35 changed files with 1,390 additions and 1,065,753 deletions.
125,524 changes: 0 additions & 125,524 deletions libs/ooxast/ooxast-util-to-jast/src/lib/handlers/__snapshots__/body.spec.ts.snap

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function citation(j: J, citation: T, parent: Parent) {
j.partialCitation = ''
console.log('Success!')
}
console.log(json)
// console.log(json)
console.log(j.partialCitation)
throw new Error(
'Corrupt citation! This might be because the text is too long.'
Expand Down
20 changes: 20 additions & 0 deletions libs/ooxast/ooxast-util-to-jast/src/lib/handlers/drawing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { all } from '../all'
import { J, Node, Root } from '../types'
import { x } from 'xastscript'
import { Article, Front, Body, Back, Fig } from 'jjast'
import { Drawing } from 'ooxast'
import { select } from 'xast-util-select'

export function drawing(j: J, node: Drawing): Fig {
const blip = select('a\\:blip', node)
if (!blip) return x('fig') as Fig
const ref = blip?.attributes?.['r:embed']
if (!ref) return x('fig') as Fig

return x('fig', [
x('inline-figure'),
x('caption'),
x('label'),
x('graphic', { 'xlink:href': j.relations[ref] }, []),
]) as Fig
}
2 changes: 2 additions & 0 deletions libs/ooxast/ooxast-util-to-jast/src/lib/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { footnote } from './footnote'
import { document } from './document'
import { r } from './r'
import { tr } from './tr'
import { drawing } from './drawing'

export const handlers = {
p,
Expand All @@ -29,6 +30,7 @@ export const handlers = {
xml: ignore,
instruction: ignore,
doctype: ignore,
drawing,
}

function ignore() {}
3 changes: 3 additions & 0 deletions libs/ooxast/ooxast-util-to-jast/src/lib/handlers/r.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export function r(j: J, node: R) {
{ type: 'text', value: `[${node?.children?.[1]?.attributes?.['w:id']}]` }
)
}
if (node?.children?.[1]?.name === 'w:drawing') {
return all(j, node)
}

if (node?.children?.[1]?.name === 'w:instrText') {
j.deleteNextRun = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function toJast(
quotes: ['"'],
topSection: 0,
columnSeparator: false,
//relations: {},
}
) {
// const byId: { [s: string]: Element } = {}
Expand Down Expand Up @@ -108,6 +109,7 @@ export function toJast(
parseCitation: options.parseCitation || parseCitation,
partialCitation: '',
deleteNextRun: false,
relations: options.relations || {},
} as Context
)

Expand Down Expand Up @@ -138,7 +140,7 @@ export function toJast(

// visit(mdast, 'text', ontext)

//console.log(citations)
//// // // console.log(citations)
const back = select('back', jast)
if (!back) return jast

Expand Down
3 changes: 3 additions & 0 deletions libs/ooxast/ooxast-util-to-jast/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface Options {
}
parseCitation?: (citation: any) => any
collectCitation?: (citation: any) => any

relations?: { [key: string]: string }
}

export type Handle = (
Expand Down Expand Up @@ -78,6 +80,7 @@ export interface Context {
collectCitation: (citation: any) => any
partialCitation: string
deleteNextRun: boolean
relations: { [key: string]: string }
}

export type JWithProps = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ export interface PosH extends UnistNode {
children: RequiredMap<PosHMap>[]
}

export interface SpecificLiteral<val extends string = string> {
type: 'text'
value: val
}
export interface PosHMap {
align: AlignHVal
posOffset: string
align: SpecificLiteral<AlignHVal>
posOffset: SpecificLiteral<string>
}

export interface PosV extends UnistNode {
Expand All @@ -130,8 +134,8 @@ export interface PosV extends UnistNode {
}

export interface PosVMap {
align: AlignVVal
posOffset: string
align: SpecificLiteral<AlignVVal>
posOffset: SpecificLiteral<string>
}

export interface TextboxInfo extends UnistNode {
Expand Down
Loading

0 comments on commit fe2b9f8

Please sign in to comment.