-
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.
feat: add references in the article (#89)
* feat: add bibtex parser * feat: successfully parse the bibtex and display it * refac: move the references to separate component * Add tabs for the preview * feat: preview * fix: add error if parse doesn't work * feat: replace cite with link * feat: style references * feat: move edit button and change download to dropdown * feat: display the references too * sh run.sh gen_api * feat: upload page add refs * sh run.sh gen_api * feat: add edit functions to refs * refac: move article editor in separate component * sh run.sh gen_api * feat: restyle so everything fits and references highlight * fix: remove base64 encoding and use raw pdb text * sh run.sh gen_api
- Loading branch information
Showing
16 changed files
with
297 additions
and
87 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
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 |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
}, | ||
"type": "module", | ||
"dependencies": { | ||
"bibtex": "^0.9.0", | ||
"marked": "^10.0.0" | ||
} | ||
} |
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,60 @@ | ||
<script lang="ts"> | ||
import { | ||
Card, | ||
Tabs, | ||
TabItem, | ||
Heading, | ||
Label, | ||
Textarea, | ||
} from "flowbite-svelte"; | ||
import Markdown from "$lib/Markdown.svelte"; | ||
import References from "$lib/References.svelte"; | ||
export let refs = ""; | ||
export let content = ""; | ||
</script> | ||
|
||
<Card | ||
class="max-w-full" | ||
style="height: 600px; overflow-y: scroll; padding: 0; padding-top: 4px; padding-left: 4px;" | ||
> | ||
<Tabs contentClass="bg-none p-5" style="underline"> | ||
<TabItem title="article content" open> | ||
<div> | ||
<Label for="content" class="block mb-2" | ||
>Protein Article (Markdown)</Label | ||
> | ||
<Textarea | ||
id="content" | ||
placeholder="Enter markdown..." | ||
rows={12} | ||
bind:value={content} | ||
/> | ||
</div> | ||
|
||
<div class="mt-3"> | ||
<Label for="refs" class="block mb-2">References (BibTeX)</Label> | ||
<Textarea | ||
id="refs" | ||
placeholder="Enter bibtex with atleast an id, title, and author (optionally url and year)" | ||
rows={4} | ||
bind:value={refs} | ||
/> | ||
</div> | ||
</TabItem> | ||
<TabItem title="preview"> | ||
{#if content.length > 0 || refs.length > 0} | ||
<Card class="max-w-full"> | ||
<Heading tag="h4">Article</Heading> | ||
<Markdown text={content} /> | ||
</Card> | ||
|
||
<Card class="max-w-full mt-5"> | ||
<Heading tag="h4">References</Heading> | ||
<References bibtex={String.raw`${refs}`} /> | ||
</Card> | ||
{:else} | ||
No content to render/preview | ||
{/if} | ||
</TabItem> | ||
</Tabs> | ||
</Card> |
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,68 @@ | ||
<script lang="ts"> | ||
/* Put stuff here */ | ||
import { parseBibFile, type BibEntry, BibFilePresenter } from "bibtex"; | ||
export let bibtex = String.raw``; | ||
let bib: BibFilePresenter; | ||
$: { | ||
try { | ||
bib = parseBibFile(bibtex); | ||
} catch (e) { | ||
console.log("error in syntax"); | ||
} | ||
} | ||
/** | ||
* @returns string of authors | ||
*/ | ||
function parseAuthors(entry: BibEntry) { | ||
const authors = entry.getFieldAsString("author"); | ||
// if a number or not found, error in parsing, so do nothing | ||
if (!authors || typeof authors === "number") | ||
return "[error in parsing authors]"; | ||
const parsed = authors.split(" and ").map((author) => | ||
author | ||
.split(",") | ||
.map((d) => d.trim()) | ||
.reverse() | ||
.join(" ") | ||
); | ||
return new Intl.ListFormat("en").format(parsed); | ||
} | ||
</script> | ||
|
||
{#if bib} | ||
{#each bib.entries_raw as entry, i} | ||
<div class={i > 0 ? "mt-5" : ""} id={entry._id}> | ||
<div class="bg-gray-50 text-gray-400"> | ||
[<span style="font-size: 15px;">{entry._id}</span>] | ||
</div> | ||
<div class="border-l-2 border-gray-400 pl-2"> | ||
<div style="font-size: 17px;"> | ||
{#if entry.getFieldAsString("url")} | ||
<a href={`${entry.getFieldAsString("url")}`}> | ||
<b> | ||
{entry.getFieldAsString("title")} | ||
</b> | ||
</a> | ||
{:else} | ||
<b> | ||
{entry.getFieldAsString("title")} | ||
</b> | ||
{/if} | ||
</div> | ||
|
||
<p>{parseAuthors(entry)}</p> | ||
{#if entry.getFieldAsString("journal")} | ||
<i> | ||
{entry.getFieldAsString("journal")} | ||
{entry.getFieldAsString("year")} | ||
</i> | ||
{/if} | ||
</div> | ||
</div> | ||
{/each} | ||
{:else} | ||
<span class="text-red-700 font-bold"> BibTeX Syntax Error </span> | ||
{/if} |
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 |
---|---|---|
|
@@ -8,5 +8,6 @@ export type ProteinEntry = { | |
length: number; | ||
mass: number; | ||
content?: (string | null); | ||
refs?: (string | null); | ||
}; | ||
|
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
Oops, something went wrong.