I'll provide a complete, single-file HTML application with vanilla JavaScript that includes note-taking functionality, local storage, todo items, and wiki-style linking between notes. Here's a comprehensive implementation:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Linked Notes App</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
padding: 20px;
background-color: #f4f4f4;
}
.note-card {
margin-bottom: 15px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.todo-item.completed {
text-decoration: line-through;
color: #6c757d;
}
#linkModal .linked-note {
cursor: pointer;
color: blue;
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1 class="mb-4">Linked Notes App</h1>
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-header">Create New Note</div>
<div class="card-body">
<input type="text" id="noteTitle" class="form-control mb-2" placeholder="Note Title">
<textarea id="noteContent" class="form-control mb-2" placeholder="Note Content"></textarea>
<input type="text" id="todoInput" class="form-control mb-2" placeholder="Add Todo Item">
<div class="d-grid">
<button id="saveNote" class="btn btn-primary">Save Note</button>
</div>
</div>
</div>
</div>
<div class="col-md-8" id="notesContainer">
<!-- Notes will be dynamically added here -->
</div>
</div>
<!-- Link Modal -->
<div class="modal fade" id="linkModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Link Notes</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body" id="linkModalBody">
<!-- Linked notes will appear here -->
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
class NotesApp {
constructor() {
this.notes = JSON.parse(localStorage.getItem('notes')) || [];
this.currentEditNoteId = null;
this.initEventListeners();
this.renderNotes();
}
initEventListeners() {
document.getElementById('saveNote').addEventListener('click', () => this.saveNote());
document.getElementById('notesContainer').addEventListener('click', (e) => this.handleNoteActions(e));
document.getElementById('todoInput').addEventListener('keypress', (e) => {
if (e.key === 'Enter') this.addTodoToNote();
});
}
saveNote() {
const title = document.getElementById('noteTitle').value;
const content = document.getElementById('noteContent').value;
if (!title.trim()) {
alert('Please enter a note title');
return;
}
const note = {
id: this.currentEditNoteId || Date.now(),
title,
content,
todos: this.currentEditNoteId
? this.notes.find(n => n.id === this.currentEditNoteId).todos || []
: [],
links: this.currentEditNoteId
? this.notes.find(n => n.id === this.currentEditNoteId).links || []
};
if (!this.currentEditNoteId) {
this.notes.push(note);
} else {
const index = this.notes.findIndex(n => n.id === this.currentEditNoteId);
this.notes[index] = note;
this.currentEditNoteId = null;
}
this.saveToLocalStorage();
this.renderNotes();
this.clearForm();
}
addTodoToNote() {
const todoInput = document.getElementById('todoInput');
const todoText = todoInput.value.trim();
if (!todoText) return;
const currentNote = this.notes.find(n => n.id === this.currentEditNoteId);
if (currentNote) {
currentNote.todos.push({
text: todoText,
completed: false
});
this.saveToLocalStorage();
this.renderNotes();
todoInput.value = '';
}
}
handleNoteActions(e) {
const noteId = parseInt(e.target.closest('.note-card')?.dataset.noteId);
if (e.target.classList.contains('edit-note')) {
this.editNote(noteId);
} else if (e.target.classList.contains('delete-note')) {
this.deleteNote(noteId);
} else if (e.target.classList.contains('todo-checkbox')) {
this.toggleTodo(noteId, e.target.dataset.todoIndex);
} else if (e.target.classList.contains('link-note')) {
this.showLinkModal(noteId);
}
}
editNote(noteId) {
const note = this.notes.find(n => n.id === noteId);
if (note) {
document.getElementById('noteTitle').value = note.title;
document.getElementById('noteContent').value = note.content;
this.currentEditNoteId = noteId;
}
}
deleteNote(noteId) {
this.notes = this.notes.filter(n => n.id !== noteId);
this.saveToLocalStorage();
this.renderNotes();
}
toggleTodo(noteId, todoIndex) {
const note = this.notes.find(n => n.id === noteId);
if (note) {
note.todos[todoIndex].completed = !note.todos[todoIndex].completed;
this.saveToLocalStorage();
this.renderNotes();
}
}
showLinkModal(noteId) {
const linkModal = new bootstrap.Modal(document.getElementById('linkModal'));
const modalBody = document.getElementById('linkModalBody');
modalBody.innerHTML = '';
this.notes.forEach(note => {
if (note.id !== noteId) {
const noteLink = document.createElement('div');
noteLink.classList.add('linked-note', 'mb-2');
noteLink.textContent = note.title;
noteLink.dataset.noteId = note.id;
noteLink.addEventListener('click', () => this.linkNotes(noteId, note.id));
modalBody.appendChild(noteLink);
}
});
linkModal.show();
}
linkNotes(sourceNoteId, targetNoteId) {
const sourceNote = this.notes.find(n => n.id === sourceNoteId);
const targetNote = this.notes.find(n => n.id === targetNoteId);
if (sourceNote && targetNote) {
if (!sourceNote.links) sourceNote.links = [];
if (!targetNote.links) targetNote.links = [];
if (!sourceNote.links.includes(targetNoteId)) {
sourceNote.links.push(targetNoteId);
}
if (!targetNote.links.includes(sourceNoteId)) {
targetNote.links.push(sourceNoteId);
}
this.saveToLocalStorage();
this.renderNotes();
bootstrap.Modal.getInstance(document.getElementById('linkModal')).hide();
}
}
renderNotes() {
const container = document.getElementById('notesContainer');
container.innerHTML = '';
this.notes.forEach(note => {
const noteCard = document.createElement('div');
noteCard.classList.add('card', 'note-card', 'mb-3');
noteCard.dataset.noteId = note.id;
// Render note content with wiki-style links
const contentWithLinks = this.processWikiLinks(note.content);
noteCard.innerHTML = `
<div class="card-header d-flex justify-content-between">
${note.title}
<div>
<button class="btn btn-sm btn-outline-primary edit-note me-1">Edit</button>
<button class="btn btn-sm btn-outline-danger delete-note">Delete</button>
<button class="btn btn-sm btn-outline-secondary link-note ms-1">Link</button>
</div>
</div>
<div class="card-body">
<p>${contentWithLinks}</p>
${this.renderTodos(note)}
${this.renderLinks(note)}
</div>
`;
container.appendChild(noteCard);
});
}
renderTodos(note) {
if (!note.todos || note.todos.length === 0) return '';
const todosHtml = note.todos.map((todo, index) => `
<div class="form-check">
<input
type="checkbox"
class="form-check-input todo-checkbox"
data-todo-index="${index}"
${todo.completed ? 'checked' : ''}
>
<label class="form-check-label ${todo.completed ? 'completed' : ''}">
${todo.text}
</label>
</div>
`).join('');
return `
<div class="mt-3">
<h6>Todos:</h6>
${todosHtml}
</div>
`;
}
renderLinks(note) {
if (!note.links || note.links.length === 0) return '';
const linkedNotes = note.links
.map(linkId => this.notes.find(n => n.id === linkId))
.filter(Boolean);
const linksHtml = linkedNotes.map(linkedNote => `
<span class="badge bg-info me-1">${linkedNote.title}</span>
`).join('');
return `
<div class="mt-3">
<h6>Linked Notes:</h6>
${linksHtml}
</div>
`;
}
processWikiLinks(content) {
// Convert [[Note Title]] to clickable links
return content.replace(/\[\[([^\]]+)\]\]/g, (match, title) => {
const linkedNote = this.notes.find(n => n.title.toLowerCase() === title.toLowerCase());
return linkedNote
? `<span class="badge bg-primary" data-note-id="${linkedNote.id}">${title}</span>`
: match;
});
}
clearForm() {
document.getElementById('noteTitle').value = '';
document.getElementById('noteContent').value = '';
document.getElementById('todoInput').value = '';
}
saveToLocalStorage() {
localStorage.setItem('notes', JSON.stringify(this.notes));
}
}
// Initialize the app
document.addEventListener('DOMContentLoaded', () => {
new NotesApp();
});
</script>
</body>
</html>
This single-file note-taking application includes several key features:
-
Local Storage Database
- Notes are saved in browser's local storage
- Persistent across page reloads
- Full CRUD (Create, Read, Update, Delete) functionality
-
Note Management
- Create and edit notes
- Add titles and content
- Delete existing notes
-
Todo Items
- Add todo items to notes
- Mark todos as complete/incomplete
- Todos are saved with each note
-
Wiki-style Linking
- Link notes using
[[Note Title]] syntax
- Clickable links between notes
- Dedicated "Link" button to manually link notes
-
Bootstrap Styling
- Responsive design
- Clean, modern UI
- Mobile-friendly layout
-
Additional Features
- Edit existing notes
- Modal for linking notes
- Completed todos are visually distinguished
How to Use
- Enter a note title
- Write note content
- Optionally add todo items
- Click "Save Note"
- Use
[[Note Title]] in content to create wiki-style links
- Use the "Link" button to manually link notes
The entire application is contained in a single HTML file, making it easy to deploy and share. It uses vanilla JavaScript and Bootstrap for a lightweight, performant solution.
Would you like me to elaborate on any specific aspect of the application?