-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement and use citation component and shorthand.
- Loading branch information
1 parent
5d8fd9a
commit 8d12126
Showing
6 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
import styles from "./styles.module.scss"; | ||
|
||
export interface Props { | ||
children?: React.ReactNode; | ||
} | ||
|
||
export default ({children}: Props) => { | ||
return ( | ||
<span className={styles.citation}>— { children }</span> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.citation { | ||
display: inline-block; | ||
width: 100%; | ||
text-align: right; | ||
font-size: 0.9em; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/framework/plugin-configs/remark-container-directives/Cite.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
ContainerDirectiveDeclaration, | ||
ContainerDirectiveTransformerProps | ||
} from "../../plugins/remark-container-directives/model"; | ||
import {Optional} from "../../util/optional"; | ||
import {jsxFlowElementFrom} from "../../plugins/shared/util/jsx-node-util"; | ||
import {ImportType} from "../../plugins/shared/models"; | ||
import {Node, Parent} from "unist"; | ||
import {Log} from "../../util/log"; | ||
|
||
interface Props extends ContainerDirectiveTransformerProps {} | ||
|
||
function flattenUniqueChildParagraph(directiveChildren: Node[]): Node[] { | ||
if (directiveChildren.length !== 1) { | ||
Log.instance.warn(`Expected exactly 1 child in Cite directive, found ${directiveChildren.length}`); | ||
return []; | ||
} | ||
|
||
const child = directiveChildren[0]; | ||
if (child.type !== 'paragraph') { | ||
Log.instance.warn(`Expected unique child in Cite directive to be of type paragraph, was ${child.type}`); | ||
return []; | ||
} | ||
|
||
return (child as Parent).children; | ||
} | ||
|
||
export default { | ||
name: 'Cite', | ||
transform: ({children}: Props) => Optional.of(jsxFlowElementFrom({ | ||
componentName: 'Citation', | ||
attributes: [] | ||
}, flattenUniqueChildParagraph(children))), | ||
esmImports: [{ | ||
sourcePackage: '@site/src/app/components/Citation', | ||
specifiers: [{type: ImportType.DEFAULT_IMPORT, name: 'Citation'}], | ||
}] | ||
} as ContainerDirectiveDeclaration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters