Skip to content

Commit

Permalink
feat: add type to quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Myllaume committed Oct 4, 2024
1 parent 7b4f483 commit a00f6e5
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 6 deletions.
16 changes: 13 additions & 3 deletions core/models/cosmoscope.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class Cosmoscope extends Graph {

const fileId = file.metas['id'] || file.metas['title'].toLowerCase();

quotesWithContexts.forEach(({ id, contexts }) => {
quotesWithContexts.forEach(({ id, type, contexts }) => {
if (!bibliography.library[id]) return;

if (referenceRecords.has(id)) {
Expand All @@ -333,19 +333,29 @@ class Cosmoscope extends Graph {
referenceRecords.set(id, {
contexts,
targets: new Set([fileId]),
type,
});
}
});
}
}

referenceRecords.forEach(({ targets, contexts }, key) => {
referenceRecords.forEach(({ targets, contexts, type }, key) => {
nodes.push(
new Node(key, bibliography.library[key]['title'] || '', [opts['references_type_label']]),
);
Array.from(targets).forEach((id) =>
links.push(
new Link(undefined, contexts, 'undefined', undefined, undefined, undefined, id, key),
new Link(
undefined,
contexts,
type || 'undefined',
undefined,
undefined,
undefined,
id,
key,
),
),
);
});
Expand Down
2 changes: 2 additions & 0 deletions core/utils/citeExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export default function extractCitations(markdown) {
thisCitation['suppress-author'] = rawPrefix.trim().endsWith('-');
if (thisCitation['suppress-author']) {
thisCitation.prefix = rawPrefix.substring(0, rawPrefix.trim().length - 1).trim();
} else if (rawPrefix.trim().endsWith(':')) {
thisCitation.type = rawPrefix.trim().slice(0, -1);
} else {
thisCitation.prefix = rawPrefix.trim();
}
Expand Down
16 changes: 16 additions & 0 deletions core/utils/citeExtractor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,22 @@ const tests = [
],
description: 'extracts an in-text citation with a URL as citekey and optional locator/suffix',
},
{
input: 'Blah blah [agreesWith: @doe99; about: @smith2000].',
expected: [
{
from: 10,
to: 49,
composite: false,
source: '[agreesWith: @doe99; about: @smith2000]',
citations: [
{ ...defaults, id: 'doe99', type: 'agreesWith' },
{ ...defaults, id: 'smith2000', type: 'about' },
],
},
],
description: 'extracts regular citation with type',
},
// The next tests check that locators without explicit page number are detected
{
input: '@{https://example.com/bib?name=foobar&date=2000} [33] says blah.',
Expand Down
3 changes: 2 additions & 1 deletion core/utils/quoteIdsWithContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ export default function quoteIdsWithContexts(markdown) {

extractParaphs(markdown).forEach((paraph) => {
extractCitations(paraph).forEach((result) => {
result.citations.forEach(({ id }) => {
result.citations.forEach(({ id, type }) => {
if (quotes[id]) {
quotes[id].contexts.add(paraph);
} else {
quotes[id] = {
contexts: new Set([paraph]),
id,
type,
};
}
});
Expand Down
14 changes: 14 additions & 0 deletions core/utils/quoteIdsWithContexts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ Second paragraph quoting @doe99.`;
]);
});

it('should parse quote with type', () => {
const text = 'First paragraph quoting [agreesWith: @smith04].';

const result = quotesWithContexts(text);

expect(result).toEqual([
expect.objectContaining({
contexts: ['First paragraph quoting [agreesWith: @smith04].'],
id: 'smith04',
type: 'agreesWith',
}),
]);
});

it('should parse many quotes per paragraph', () => {
const text = `First paragraph quoting @smith04.
Expand Down
3 changes: 3 additions & 0 deletions e2e/citeproc/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ link_types:
adjacent concept:
stroke: dotted
color: "#e1e1e1"
agreesWith:
stroke: simple
color: "green"
references_as_nodes: true
references_type_label: "reference"
record_filters: []
Expand Down
3 changes: 2 additions & 1 deletion e2e/record.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ describe('Record', () => {
cy.get('@backlink').find('.highlight').should('have.text', 'tools for thought');
});

it('should link type', () => {
it('should display link type', () => {
cy.get('@backlink').should('contain.text', 'adjacent concept');
cy.get('@link').should('contain.text', 'agreesWith');
});
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/records/tools-for-thought.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ tag:
- quotes
---

« Tools to augment human intelligence » [@engelbart1962; quoted by @matuschak2019].
« Tools to augment human intelligence » [agreesWith: @engelbart1962; quoted by @matuschak2019].

![alt text](otlet.jpg "Title")

0 comments on commit a00f6e5

Please sign in to comment.