Skip to content

Commit

Permalink
Merge pull request #169 from Stardown-app/docs
Browse files Browse the repository at this point in the history
Improve docs, error handling, & content extraction
  • Loading branch information
wheelercj authored Dec 6, 2024
2 parents b666833 + de6b314 commit d66753d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/alternatives.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can use this [bookmarklet](https://en.wikipedia.org/wiki/Bookmarklet) I made

## Integrate directly with an editor

* Some editors like Word and Obsidian try to convert pasted HTML, but the result tends to have formatting errors and important parts missing. Stardown's output is often significantly better because it can see more than just what's in the clipboard, and because its HTML converter is not a low-priority side feature.
* Some editors like Obsidian try to convert pasted HTML, but the result often has formatting errors and important parts missing. Stardown's output is often significantly better because it can see more than just what's in the clipboard, and because its HTML converter is not a low-priority side feature. Many popular markdown editors including GitHub don't convert to markdown at all.
* [Obsidian Clipper](https://github.com/obsidianmd/obsidian-clipper)
* [Notion Web Clipper](https://www.notion.so/web-clipper)
* [Evernote Web Clipper](https://evernote.com/features/webclipper)
Expand Down
10 changes: 5 additions & 5 deletions rollup.config.chrome.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default [
dest: 'chrome',
},
],
hook: 'buildStart', // Run the copy before the build starts.
hook: 'buildStart', // run the copy before the build starts
}),
]
},
Expand Down Expand Up @@ -83,14 +83,14 @@ export default [
// Delete all files in the `chrome` directory that were imported into
// other files there and are no longer needed.
targets: [
'chrome/*', // Delete all files except the ones below.
'chrome/*', // delete all files except the ones below

'!chrome/images',

'!chrome/manifest.json',

'!chrome/*.html',
'!chrome/*.css',
'!chrome/**/*.html',
'!chrome/**/*.css',

'!chrome/browserSpecific.js',
'!chrome/background.js',
Expand All @@ -101,7 +101,7 @@ export default [
'!chrome/text-fragment-utils.js',
'!chrome/fragment-generation-utils.js',
],
hook: 'buildEnd', // Run the delete after the build ends.
hook: 'buildEnd', // run the delete after the build ends
})
]
}
Expand Down
14 changes: 7 additions & 7 deletions rollup.config.firefox.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default [
targets: [
{
// copy the images folder and html & css files
src: ['src/images', 'src/*.html', 'src/*.css'],
src: ['src/images', 'src/**/*.html', 'src/**/*.css'],
dest: 'firefox',
},
{
Expand All @@ -80,8 +80,8 @@ export default [
transform: transform,
},
],
flatten: false,
hook: 'buildStart', // Run the copy before the build starts.
flatten: false, // don't combine all nested folders into one flat folder
hook: 'buildStart', // run the copy before the build starts
}),
]
},
Expand Down Expand Up @@ -117,14 +117,14 @@ export default [
// Delete all files in the `firefox` directory that were imported into
// other files there and are no longer needed.
targets: [
'firefox/*', // Delete all files except the ones below.
'firefox/*', // delete all files except the ones below

'!firefox/images',

'!firefox/manifest.json',

'!firefox/*.html',
'!firefox/*.css',
'!firefox/**/*.html',
'!firefox/**/*.css',

'!firefox/browserSpecific.js',
'!firefox/background.js',
Expand All @@ -135,7 +135,7 @@ export default [
'!firefox/text-fragment-utils.js',
'!firefox/fragment-generation-utils.js',
],
hook: 'buildEnd', // Run the delete after the build ends.
hook: 'buildEnd', // run the delete after the build ends
})
]
}
Expand Down
5 changes: 3 additions & 2 deletions src/contentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function handleCopyRequest(text) {

try {
await navigator.clipboard.writeText(text);
console.log('Successfully wrote text to the clipboard.');
} catch (err) {
console.warn('navigator.clipboard.writeText:', err.message);
console.log('Using fallback method to write text to the clipboard.');
Expand All @@ -69,10 +70,11 @@ export async function handleCopyRequest(text) {

try {
document.execCommand('copy');
console.log('No error thrown by the fallback method.');
} catch (fallbackError) {
console.error(
'Failed to write text to the clipboard using fallback method because:',
fallbackError
fallbackError.message,
);
return {
status: 0, // failure
Expand All @@ -84,7 +86,6 @@ export async function handleCopyRequest(text) {
}
}

console.log('Successfully wrote text to the clipboard.');
return {
status: 1, // successfully copied one item
notifTitle: 'Text copied',
Expand Down
10 changes: 7 additions & 3 deletions src/extractMainContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ import { isProbablyReaderable } from './Readability-readerable.js'
* @returns {Promise<DocumentFragment>}
*/
export async function extractMainContent(frag, location) {
// prevent extraction of main content for certain sites
if (location.hostname === 'news.ycombinator.com') {
// Readability.js would remove all HN comments
return frag;
}

let newFrag = null;
if (location.href.match(/^https:\/\/(?:[^\/]+\.)?wikipedia\.org\/wiki\/.*/)) {
newFrag = extractWikipediaArticle(frag);
} else if (location.href.match(/^https:\/\/github\.com\/[^/]+\/[^/]+\/issues\/\d+/)) {
newFrag = extractGithubIssue(frag);
} else if (location.hostname === 'news.ycombinator.com') {
// Running Readability.js on HN removes all comments, so prevent that.
return frag;
}
if (newFrag) {
return newFrag;
Expand Down Expand Up @@ -107,6 +110,7 @@ function extractGithubIssue(frag) {
'.Details-content--hidden',
'.discussion-timeline-actions',
'div.text-right code',
'span.State',
];
content.querySelectorAll(toRemove.join(',')).forEach(el => el.remove());

Expand Down

0 comments on commit d66753d

Please sign in to comment.