mirror of
https://github.com/lossless-group/perplexed-plugin.git
synced 2026-07-22 06:49:50 +00:00
improve(modal): isolate final reference for conversion to hex
On branch development Changes to be committed: modified: src/modals/CitationModal.ts modified: src/services/citationService.ts modified: src/styles/citations.css
This commit is contained in:
parent
7337a11172
commit
6d616c9a63
3 changed files with 91 additions and 18 deletions
|
|
@ -94,12 +94,23 @@ export class CitationModal extends Modal {
|
|||
|
||||
// Add each citation instance
|
||||
group.matches.forEach((match, matchIndex) => {
|
||||
const instanceEl = content.createDiv('cite-wide-instance');
|
||||
const isRefSource = match.isReferenceSource === true;
|
||||
const instanceEl = content.createDiv(`cite-wide-instance ${isRefSource ? 'cite-wide-reference-source' : ''}`);
|
||||
|
||||
// Show line number and preview
|
||||
const lineInfo = instanceEl.createDiv('cite-wide-line-info');
|
||||
|
||||
// Add a special badge for reference sources
|
||||
if (isRefSource) {
|
||||
lineInfo.createEl('span', {
|
||||
text: 'Reference',
|
||||
cls: 'cite-wide-badge cite-wide-badge-reference'
|
||||
});
|
||||
lineInfo.createEl('span', { text: ' • ' });
|
||||
}
|
||||
|
||||
lineInfo.createEl('span', {
|
||||
text: `Line ${match.lineNumber + 1}: `,
|
||||
text: `Line ${match.lineNumber}: `,
|
||||
cls: 'cite-wide-line-number'
|
||||
});
|
||||
|
||||
|
|
@ -117,25 +128,31 @@ export class CitationModal extends Modal {
|
|||
// Add view and convert buttons
|
||||
const btnContainer = instanceEl.createDiv('cite-wide-instance-actions');
|
||||
|
||||
const viewBtn = btnContainer.createEl('button', {
|
||||
text: 'View',
|
||||
cls: 'mod-cta-outline cite-wide-view-btn'
|
||||
});
|
||||
// Only add view/convert buttons for non-reference entries
|
||||
if (!isRefSource) {
|
||||
const viewBtn = btnContainer.createEl('button', {
|
||||
text: 'View',
|
||||
cls: 'mod-cta-outline cite-wide-view-btn'
|
||||
});
|
||||
|
||||
viewBtn.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
this.scrollToLine(match.lineNumber);
|
||||
});
|
||||
viewBtn.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
this.scrollToLine(match.lineNumber);
|
||||
});
|
||||
}
|
||||
|
||||
const convertBtn = btnContainer.createEl('button', {
|
||||
text: 'Convert',
|
||||
cls: 'mod-cta cite-wide-convert-btn'
|
||||
});
|
||||
// Only add convert button for non-reference entries
|
||||
if (!isRefSource) {
|
||||
const convertBtn = btnContainer.createEl('button', {
|
||||
text: 'Convert',
|
||||
cls: 'mod-cta cite-wide-convert-btn'
|
||||
});
|
||||
|
||||
convertBtn.addEventListener('click', async (e) => {
|
||||
e.stopPropagation();
|
||||
await this.convertCitationInstance(group, matchIndex);
|
||||
});
|
||||
convertBtn.addEventListener('click', async (e) => {
|
||||
e.stopPropagation();
|
||||
await this.convertCitationInstance(group, matchIndex);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ export interface CitationMatch {
|
|||
index: number;
|
||||
lineContent: string;
|
||||
lineNumber: number;
|
||||
isReferenceSource?: boolean; // Flag to indicate if this is a reference source entry
|
||||
}
|
||||
|
||||
export interface CitationGroup {
|
||||
|
|
@ -173,6 +174,25 @@ export class CitationService {
|
|||
const source = this.findReferenceSourceInFootnotes(content, number);
|
||||
if (source && typeof source === 'string' && source.trim() !== '') {
|
||||
referenceSources.set(number, source);
|
||||
|
||||
// Add the reference source as a special match
|
||||
const referenceLine = content.split('\n').findIndex(line => {
|
||||
const match = line.trim().match(new RegExp(`^${number}\\.\\s+`));
|
||||
return !!match;
|
||||
});
|
||||
|
||||
if (referenceLine !== -1) {
|
||||
matches.push({
|
||||
type: 'reference',
|
||||
number,
|
||||
original: `${number}. ${source}`,
|
||||
index: content.indexOf(`${number}. `, referenceLine > 0 ?
|
||||
content.split('\n').slice(0, referenceLine).join('\n').length : 0),
|
||||
lineContent: `${number}. ${source}`,
|
||||
lineNumber: referenceLine + 1,
|
||||
isReferenceSource: true
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
border-top: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
/* Base instance styling */
|
||||
.cite-wide-instance {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
|
@ -69,6 +70,16 @@
|
|||
border-bottom: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
/* Reference source specific styling */
|
||||
.cite-wide-instance.cite-wide-reference-source {
|
||||
background-color: var(--background-secondary-alt);
|
||||
margin: 0 -1rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-left: 3px solid var(--interactive-accent);
|
||||
}
|
||||
|
||||
.cite-wide-instance:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
|
@ -91,6 +102,31 @@
|
|||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* Badge styling */
|
||||
.cite-wide-badge {
|
||||
display: inline-block;
|
||||
padding: 0.15em 0.5em;
|
||||
font-size: 0.75em;
|
||||
font-weight: 600;
|
||||
line-height: 1.2;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
vertical-align: baseline;
|
||||
border-radius: 3px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.cite-wide-badge-reference {
|
||||
color: var(--text-normal);
|
||||
background-color: var(--background-modifier-border);
|
||||
}
|
||||
|
||||
/* Adjust line info spacing when badge is present */
|
||||
.cite-wide-line-info > .cite-wide-badge + span {
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.cite-wide-instance-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
|
|
|
|||
Loading…
Reference in a new issue