Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Added backlink to initial reference
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Jul 5, 2020
1 parent 317c028 commit c4c5933
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
22 changes: 16 additions & 6 deletions src/editor/plugins/Footnote/FootnotesBlockView.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import genkey from 'weak-key';
import React from 'react';
import { Node } from 'slate';
import {
Expand All @@ -16,6 +17,7 @@ const getBlocks = (properties) => {

const FootnotesBlockView = (props) => {
const { data, properties } = props;
const { title } = data;

// console.log(properties);
const blocks = getBlocks(properties);
Expand All @@ -36,16 +38,24 @@ const FootnotesBlockView = (props) => {
});

return (
<>
<h3>{data.title}</h3>
<div className="footnotes-listing-block">
<h3>{title}</h3>
{footnotes && (
<ul>
{footnotes.map((data) => (
<li>{data.footnote}</li>
))}
{footnotes.map((data) => {
const key = genkey(data);
return (
<li key={key} id={`footnote-${key}`}>
{data.footnote}
<a href={`#ref-${key}`} aria-label="Back to content">
</a>
</li>
);
})}
</ul>
)}
</>
</div>
);
};

Expand Down
11 changes: 8 additions & 3 deletions src/editor/plugins/Footnote/render.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import genkey from 'weak-key';

export const FootnoteElement = ({ attributes, children, element, mode }) => {
const { data = {} } = element;
const { footnote } = data;
console.log('footnote mode', mode);
// const { footnote } = data;
// console.log('footnote mode', mode);
// {mode === 'view' && (
// <span className="footnote-text" style={{ display: 'inline' }}>
// {footnote}
// </span>
// )}
const key = genkey(data);
return (
<>
{mode === 'view' ? (
<a href={`#footnote-${genkey(data)}`} aria-describedby="footnote-label">
<a
href={`#footnote-${key}`}
id={`ref-${key}`}
aria-describedby="footnote-label"
>
{children}
</a>
) : (
Expand Down
6 changes: 6 additions & 0 deletions src/editor/plugins/Footnote/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ a[aria-describedby='footnote-label']:focus::after {
outline: thin dotted;
outline-offset: 2px;
}

.footnotes-listing-block {
& :target {
background: yellow;
}
}

0 comments on commit c4c5933

Please sign in to comment.