Below you’ll find a complete one-file, zero-dependency*, Bootstrap-styled notes application.
Just copy-paste it into an index.html and open it in any modern browser. ✨
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>One-file Notes</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap 5 (via CDN) -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { height:100vh; }
#noteList { overflow-y:auto; max-height: 80vh; }
textarea { height:60vh; }
.checked { text-decoration: line-through; color:#888; }
.wikilink { cursor:pointer; text-decoration:underline; }
</style>
</head>
<body class="p-3">
<div class="container-fluid">
<div class="row">
<!-- ─────────── Sidebar ─────────── -->
<div class="col-12 col-md-3 mb-3">
<div class="d-flex mb-2">
<input id="search" class="form-control me-2" placeholder="Search">
<button id="newNote" class="btn btn-primary">+</button>
</div>
<ul id="noteList" class="list-group"></ul>
</div>
<!-- ─────────── Editor / Viewer ─────────── -->
<div class="col-12 col-md-9">
<input id="noteTitle" class="form-control mb-2" placeholder="Title">
<textarea id="noteContent" class="form-control mb-2"
placeholder="Write your note… • - [ ] todo • [[wiki link]]"></textarea>
<div class="mb-2">
<button id="saveBtn" class="btn btn-success me-2">Save</button>
<button id="deleteBtn" class="btn btn-danger me-2">Delete</button>
<button id="previewBtn" class="btn btn-secondary">Preview</button>
</div>
<!-- Rendered (read-only) view -->
<div id="preview" class="border p-3 rounded" style="display:none;"></div>
</div>
</div>
</div>
<script>
/* ========= Local-storage helpers ========= */
const STORAGE_KEY = 'notesData';
let notes = loadNotes(); // { id : {id,title,content} }
let currentId = null;
function loadNotes() { return JSON.parse(localStorage.getItem(STORAGE_KEY) || '{}'); }
function saveNotes() { localStorage.setItem(STORAGE_KEY, JSON.stringify(notes)); }
/* ========= DOM Shorthands ========= */
const $list = document.getElementById('noteList');
const $title = document.getElementById('noteTitle');
const $content = document.getElementById('noteContent');
const $preview = document.getElementById('preview');
/* ========= Sidebar (list) ========= */
function renderList(filter='') {
$list.innerHTML='';
Object.values(notes)
.filter(n => n.title.toLowerCase().includes(filter.toLowerCase()))
.sort((a,b)=>a.title.localeCompare(b.title))
.forEach(n=>{
const li=document.createElement('li');
li.className='list-group-item list-group-item-action';
li.textContent=n.title||'(untitled)';
if(n.id===currentId) li.classList.add('active');
li.onclick=()=>loadNote(n.id);
$list.appendChild(li);
});
}
/* ========= CRUD ========= */
function newNote() {
const id='id-'+Date.now();
notes[id]={id,title:'',content:''};
saveNotes(); renderList(); loadNote(id);
}
function loadNote(id){
currentId=id;
const n=notes[id];
$title.value = n.title;
$content.value= n.content;
hidePreview(); renderList(document.getElementById('search').value);
}
function deleteCurrent(){
if(!currentId) return;
if(!confirm('Delete note?')) return;
delete notes[currentId]; saveNotes(); currentId=null;
$title.value=''; $content.value=''; $preview.innerHTML='';
renderList();
}
function saveCurrent(){
if(!currentId) newNote();
const n=notes[currentId];
n.title = $title.value.trim()||'(untitled)';
n.content= $content.value;
saveNotes(); renderList(document.getElementById('search').value);
}
/* ========= Preview Rendering ========= */
function showPreview(){
renderPreview($content.value);
$preview.style.display='';
$content.style.display='none';
document.getElementById('previewBtn').textContent='Edit';
}
function hidePreview(){
$preview.style.display='none';
$content.style.display='';
document.getElementById('previewBtn').textContent='Preview';
}
function renderPreview(text){
// 1. escape HTML
let html=text.replace(/</g,'<').replace(/>/g,'>');
// 2. to-do items → checkboxes
html=html.replace(/^(\s*)-\s\[\s\]\s(.*)$/gm,
(_,spaces,t)=>`${spaces}<input type="checkbox" class="todo"> ${t}`
).replace(/^(\s*)-\s\[x\]\s(.*)$/gim,
(_,spaces,t)=>`${spaces}<input type="checkbox" class="todo" checked> <span class="checked">${t}</span>`
);
// 3. wiki links [[Title]]
html=html.replace(/\[\[([^\]]+)\]\]/g,
(_,title)=>`<a href="#" class="wikilink" data-title="${title}">${title}</a>`
);
// 4. line breaks → <br>
html=html.replace(/\n/g,'<br>');
$preview.innerHTML=html;
/* ► Attach behaviour ◄ */
// toggle todo
$preview.querySelectorAll('.todo').forEach(cb=>{
cb.addEventListener('change',()=>{
const lines=$content.value.split('\n');
let idxTarget = [...$preview.querySelectorAll('.todo')].indexOf(cb), seen=-1;
for(let i=0;i<lines.length;i++){
if(lines[i].match(/^\s*-\s\[( |x)\]\s/)){
if(++seen===idxTarget){
lines[i]=lines[i].startsWith('- [ ]')
? lines[i].replace('- [ ]','- [x]')
: lines[i].replace('- [x]','- [ ]');
break;
}
}
}
$content.value=lines.join('\n'); saveCurrent(); renderPreview($content.value);
});
});
// follow / create wiki link
$preview.querySelectorAll('.wikilink').forEach(a=>{
a.addEventListener('click',e=>{
e.preventDefault();
const title=a.dataset.title.trim();
let note=Object.values(notes).find(n=>n.title===title);
if(!note){ // auto-create
const id='id-'+Date.now();
note={id,title,content:''};
notes[id]=note; saveNotes();
}
renderList(); loadNote(note.id);
});
});
}
/* ========= Events ========= */
document.getElementById('newNote').onclick = newNote;
document.getElementById('saveBtn').onclick = saveCurrent;
document.getElementById('deleteBtn').onclick = deleteCurrent;
document.getElementById('previewBtn').onclick=()=>{
$preview.style.display==='none'?showPreview():hidePreview();
};
document.getElementById('search').oninput=e=>renderList(e.target.value);
/* ========= first render ========= */
renderList();
</script>
</body>
</html>