Here's a simple implementation of a local site using only HTML, CSS, and Python that meets your requirements.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Task Tables</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1000px;
margin: 0 auto;
padding: 20px;
}
.table-container {
margin-bottom: 30px;
border: 1px solid #ddd;
border-radius: 5px;
padding: 15px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 15px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.table-title {
font-size: 1.2em;
margin-bottom: 10px;
font-weight: bold;
}
.controls {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
button {
padding: 8px 12px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.add-row {
background-color: #2196F3;
}
.add-row:hover {
background-color: #0b7dda;
}
.copy-md {
background-color: #ff9800;
}
.copy-md:hover {
background-color: #e68a00;
}
.add-table {
display: block;
margin: 20px auto;
padding: 10px 15px;
font-size: 1.1em;
}
.new-table-form {
margin-top: 30px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
display: none;
}
input[type="text"] {
padding: 8px;
width: 100%;
margin-bottom: 10px;
box-sizing: border-box;
}
.checkbox {
width: 20px;
height: 20px;
}
</style>
</head>
<body>
<h1>Markdown Task Tables</h1>
<div id="tables-container"></div>
<button id="show-add-table" class="add-table">+ ADD NEW TABLE</button>
<div id="new-table-form" class="new-table-form">
<h2>Create New Table</h2>
<input type="text" id="table-title" placeholder="Table Title">
<button id="create-table">Create Table</button>
</div>
<script>
const tablesContainer = document.getElementById('tables-container');
const showAddTableButton = document.getElementById('show-add-table');
const newTableForm = document.getElementById('new-table-form');
const createTableButton = document.getElementById('create-table');
const tableTitleInput = document.getElementById('table-title');
let tables = [];
// Load tables from local storage
if (localStorage.getItem('tables')) {
tables = JSON.parse(localStorage.getItem('tables'));
renderTables();
}
showAddTableButton.addEventListener('click', () => {
newTableForm.style.display = 'block';
});
createTableButton.addEventListener('click', () => {
const title = tableTitleInput.value.trim();
if (title) {
const newTable = {
title: title,
tasks: []
};
tables.push(newTable);
renderTables();
tableTitleInput.value = '';
newTableForm.style.display = 'none';
}
});
function renderTables() {
tablesContainer.innerHTML = '';
tables.forEach((table, index) => {
const tableContainer = document.createElement('div');
tableContainer.className = 'table-container';
const titleDiv = document.createElement('div');
titleDiv.className = 'table-title';
titleDiv.textContent = table.title;
tableContainer.appendChild(titleDiv);
const tableEl = document.createElement('table');
// Create header
const thead = document.createElement('thead');
const headerRow = document.createElement('tr');
const headers = ['Task', 'Status'];
headers.forEach(header => {
const th = document.createElement('th');
th.textContent = header;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
tableEl.appendChild(thead);
// Create body
const tbody = document.createElement('tbody');
table.tasks.forEach((task, taskIndex) => {
const row = document.createElement('tr');
const taskCell = document.createElement('td');
const taskInput = document.createElement('input');
taskInput.type = 'text';
taskInput.value = task.name;
taskInput.className = 'task-name';
taskCell.appendChild(taskInput);
const statusCell = document.createElement('td');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.className = 'checkbox';
checkbox.checked = task.done;
statusCell.appendChild(checkbox);
row.appendChild(taskCell);
row.appendChild(statusCell);
tbody.appendChild(row);
});
// Add new row button
const newRowButton = document.createElement('button');
newRowButton.className = 'add-row';
newRowButton.textContent = '+ Add Task';
newRowButton.addEventListener('click', () => {
const newRow = document.createElement('tr');
const taskCell = document.createElement('td');
const taskInput = document.createElement('input');
taskInput.type = 'text';
taskInput.className = 'task-name';
taskCell.appendChild(taskInput);
const statusCell = document.createElement('td');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.className = 'checkbox';
statusCell.appendChild(checkbox);
newRow.appendChild(taskCell);
newRow.appendChild(statusCell);
tbody.appendChild(newRow);
});
tableEl.appendChild(tbody);
tableContainer.appendChild(tableEl);
// Copy table as markdown button
const copyMdButton = document.createElement('button');
copyMdButton.className = 'copy-md';
copyMdButton.textContent = 'Copy as Markdown';
copyMdButton.addEventListener('click', () => {
const markdown = getTableMarkdown(table);
navigator.clipboard.writeText(markdown).then(() => {
alert('Markdown copied to clipboard!');
});
});
tableContainer.appendChild(copyMdButton);
// Save changes button
const saveChangesButton = document.createElement('button');
saveChangesButton.textContent = 'Save Changes';
saveChangesButton.addEventListener('click', () => {
const tasks = [];
const rows = tbody.children;
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const taskName = row.children[0].children[0].value.trim();
const isDone = row.children[1].children[0].checked;
if (taskName) {
tasks.push({ name: taskName, done: isDone });
}
}
tables[index].tasks = tasks;
localStorage.setItem('tables', JSON.stringify(tables));
});
tableContainer.appendChild(saveChangesButton);
tablesContainer.appendChild(tableContainer);
});
// Save tables to local storage
localStorage.setItem('tables', JSON.stringify(tables));
}
function getTableMarkdown(table) {
let markdown = `## ${table.title}\n\n`;
markdown += '| Task | Status |\n';
markdown += '| ---- | ------ |\n';
table.tasks.forEach(task => {
const status = task.done ? 'X' : ' ';
markdown += `| ${task.name} | ${status} |\n`;
});
return markdown;
}
</script>
</body>
</html>
This code creates a simple web page that allows you to create tables, add tasks to tables, mark tasks as done or not done, and copy tables as markdown. The tables are stored in local storage, so they will persist even after you close the browser.
Please note that this code does not use any backend or server-side technology. It's a pure client-side application that runs entirely in the browser.
To use this code, simply save it as an HTML file and open it in your browser. You can then create tables, add tasks, and copy tables as markdown.
I hope this helps! Let me know if you have any questions or need further assistance.