Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
add static publication list block
Browse files Browse the repository at this point in the history
  • Loading branch information
dsifford committed Dec 28, 2018
1 parent f958694 commit 75785d8
Show file tree
Hide file tree
Showing 10 changed files with 514 additions and 21 deletions.
64 changes: 46 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -87,7 +87,7 @@
"browser-sync": "^2.26.3",
"browser-sync-webpack-plugin": "^2.2.2",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^2.0.2",
"css-loader": "^2.1.0",
"custom-event-polyfill": "^1.0.6",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
Expand All @@ -104,11 +104,11 @@
"rollbar": "^2.5.1",
"rollbar-sourcemap-webpack-plugin": "^2.5.0",
"sass-loader": "^7.1.0",
"snapshot-diff": "^0.4.1",
"snapshot-diff": "^0.4.2",
"style-loader": "^0.23.1",
"stylelint": "^9.9.0",
"stylelint-config-recommended-scss": "^3.2.0",
"stylelint-scss": "^3.4.3",
"stylelint-scss": "^3.4.4",
"ts-jest": "^23.10.5",
"ts-node": "^7.0.1",
"tslint": "^5.12.0",
Expand Down
2 changes: 2 additions & 0 deletions src/js/editor.ts
Expand Up @@ -4,6 +4,7 @@ import { registerPlugin } from '@wordpress/plugins';
import { registerFormatType } from '@wordpress/rich-text';

import bibliographyBlock from 'gutenberg/blocks/bibliography';
import staticBibliographyBlock from 'gutenberg/blocks/static-bibliography';
import citationFormat from 'gutenberg/formats/citation';
import Sidebar from 'gutenberg/sidebar';
import { dataStore, uiStore } from 'stores';
Expand All @@ -19,3 +20,4 @@ registerPlugin('academic-bloggers-toolkit', {
registerFormatType('abt/citation', citationFormat);

registerBlockType('abt/bibliography', bibliographyBlock);
registerBlockType('abt/static-bibliography', staticBibliographyBlock);
33 changes: 33 additions & 0 deletions src/js/gutenberg/blocks/index.ts
Expand Up @@ -2,3 +2,36 @@ export interface BibItem {
content: string;
id: string;
}

export function stripListItem(item: string): string;
export function stripListItem(item: Element): string;
export function stripListItem(item: Element | string): string {
if (typeof item === 'string') {
const container = document.createElement('div');
container.innerHTML = item;
const child = container.querySelector('.csl-entry');
if (child) {
item = child;
} else {
throw new Error(
'Outer HTML of item must be a div with className "csl-entry"',
);
}
}
const content = item;
let toRemove: Element[] = [];
for (const el of item.children) {
if (el.classList.contains('csl-indent')) {
break;
}
if (el.classList.contains('csl-left-margin')) {
toRemove = [...toRemove, el];
continue;
}
if (el.classList.contains('csl-right-inline')) {
el.outerHTML = el.innerHTML;
}
}
toRemove.forEach(el => content.removeChild(el));
return content.innerHTML.trim();
}

0 comments on commit 75785d8

Please sign in to comment.