Compare commits
No commits in common. "092f321478b0e9474182ea2f3896469452eb5a27" and "77a4f86953bac0124b509eb7045a4930254ff83a" have entirely different histories.
092f321478
...
77a4f86953
194
Obsidean.cs
194
Obsidean.cs
|
@ -1,3 +1,4 @@
|
|||
|
||||
using System.Text.RegularExpressions;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
@ -30,7 +31,7 @@ namespace libObsidean
|
|||
string path = (string)vault.Value["path"];
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
// Añadir una barra al final asegura que Path.GetDirectoryName funcione correctamente
|
||||
// Añadir una barra al final asegura que Path.GetDirectoryName funcione correctamente
|
||||
string lastDirectoryName = Path.GetFileName(Path.GetDirectoryName(path.TrimEnd('\\') + "\\"));
|
||||
|
||||
if (lastDirectoryName.Equals(vaultName, StringComparison.OrdinalIgnoreCase))
|
||||
|
@ -58,7 +59,7 @@ namespace libObsidean
|
|||
technicalTerms = ExtractTechnicalTerms(lines);
|
||||
}
|
||||
|
||||
// Ahora puedes usar technicalTerms para tu lógica de corrección
|
||||
// Ahora puedes usar technicalTerms para tu lógica de corrección
|
||||
}
|
||||
|
||||
public string[,] LeerPasswords()
|
||||
|
@ -85,128 +86,13 @@ namespace libObsidean
|
|||
}
|
||||
}
|
||||
|
||||
public string[,] LeerShortcuts()
|
||||
{
|
||||
string pathToMarkdown = GetVaultPath("VM");
|
||||
if (!string.IsNullOrEmpty(pathToMarkdown))
|
||||
{
|
||||
string pathToTabla = Path.Combine(pathToMarkdown, "DB", "Shortcuts", "Shortcuts.md");
|
||||
// Si el archivo no existe, devolver cabecera vacía
|
||||
if (!File.Exists(pathToTabla))
|
||||
{
|
||||
// Crear el directorio si hace falta
|
||||
string? dir = Path.GetDirectoryName(pathToTabla);
|
||||
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
string[,] vacio = new string[2, 4] { { "Application", "Shortcut", "Description", "IsFavorite" }, { "", "", "", "false" } };
|
||||
SaveTableToMarkdown(pathToTabla, vacio);
|
||||
return vacio;
|
||||
}
|
||||
return ParseTableFromMarkdown(pathToTabla);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string[,] LeerShortcutsPorAplicacion(string applicationName)
|
||||
{
|
||||
var tabla = LeerShortcuts();
|
||||
if (tabla == null)
|
||||
return null;
|
||||
|
||||
// Filtrar aplicando la primera columna (Application)
|
||||
List<string[]> filas = new List<string[]>();
|
||||
for (int i = 1; i < tabla.GetLength(0); i++)
|
||||
{
|
||||
if (string.Equals(tabla[i, 0], applicationName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string isFavorite = tabla.GetLength(1) > 3 ? tabla[i, 3] : "false";
|
||||
filas.Add(new[] { tabla[i, 0], tabla[i, 1], tabla[i, 2], isFavorite });
|
||||
}
|
||||
}
|
||||
|
||||
if (filas.Count == 0)
|
||||
return new string[0, 0];
|
||||
|
||||
string[,] resultado = new string[filas.Count + 1, 4];
|
||||
// Copiar cabeceras
|
||||
resultado[0, 0] = "Application";
|
||||
resultado[0, 1] = "Shortcut";
|
||||
resultado[0, 2] = "Description";
|
||||
resultado[0, 3] = "IsFavorite";
|
||||
for (int i = 0; i < filas.Count; i++)
|
||||
{
|
||||
resultado[i + 1, 0] = filas[i][0];
|
||||
resultado[i + 1, 1] = filas[i][1];
|
||||
resultado[i + 1, 2] = filas[i][2];
|
||||
resultado[i + 1, 3] = filas[i][3];
|
||||
}
|
||||
return resultado;
|
||||
}
|
||||
|
||||
public void AgregarOSobrescribirShortcut(string applicationName, string shortcut, string description, bool isFavorite = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(applicationName) || string.IsNullOrWhiteSpace(shortcut))
|
||||
return;
|
||||
|
||||
var tabla = LeerShortcuts();
|
||||
if (tabla == null)
|
||||
return;
|
||||
|
||||
bool encontrado = false;
|
||||
for (int i = 1; i < tabla.GetLength(0); i++)
|
||||
{
|
||||
if (string.Equals(tabla[i, 0], applicationName, StringComparison.OrdinalIgnoreCase) &&
|
||||
string.Equals(tabla[i, 1], shortcut, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Sobrescribir descripción
|
||||
tabla[i, 2] = description;
|
||||
if (tabla.GetLength(1) > 3)
|
||||
tabla[i, 3] = isFavorite.ToString().ToLower();
|
||||
encontrado = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!encontrado)
|
||||
{
|
||||
// Añadir nueva fila
|
||||
int filas = tabla.GetLength(0);
|
||||
int columnas = Math.Max(tabla.GetLength(1), 4); // Asegurar al menos 4 columnas
|
||||
string[,] nuevaTabla = new string[filas + 1, columnas];
|
||||
for (int i = 0; i < filas; i++)
|
||||
{
|
||||
for (int j = 0; j < tabla.GetLength(1); j++)
|
||||
{
|
||||
nuevaTabla[i, j] = tabla[i, j];
|
||||
}
|
||||
// Rellenar columnas nuevas si es necesario
|
||||
for (int j = tabla.GetLength(1); j < columnas; j++)
|
||||
{
|
||||
nuevaTabla[i, j] = j == 3 ? "false" : "";
|
||||
}
|
||||
}
|
||||
nuevaTabla[filas, 0] = applicationName;
|
||||
nuevaTabla[filas, 1] = shortcut;
|
||||
nuevaTabla[filas, 2] = description;
|
||||
nuevaTabla[filas, 3] = isFavorite.ToString().ToLower();
|
||||
tabla = nuevaTabla;
|
||||
}
|
||||
|
||||
string pathToMarkdown = GetVaultPath("VM");
|
||||
if (!string.IsNullOrEmpty(pathToMarkdown))
|
||||
{
|
||||
string pathToTabla = Path.Combine(pathToMarkdown, "DB", "Shortcuts", "Shortcuts.md");
|
||||
SaveTableToMarkdown(pathToTabla, tabla);
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<string> ExtractTechnicalTerms(string[] lines)
|
||||
{
|
||||
var terms = new HashSet<string>();
|
||||
foreach (var line in lines)
|
||||
{
|
||||
// Suponiendo que cada línea contiene un término técnico
|
||||
// Suponiendo que cada línea contiene un término técnico
|
||||
terms.Add(line.Trim());
|
||||
}
|
||||
return terms;
|
||||
|
@ -218,27 +104,27 @@ namespace libObsidean
|
|||
return Regex.Replace(text, @"\b(\w+)\b", match =>
|
||||
{
|
||||
string word = match.Groups[1].Value;
|
||||
// Verificar si la palabra está en el conjunto de términos técnicos
|
||||
// Verificar si la palabra está en el conjunto de términos técnicos
|
||||
if (technicalTerms.Contains(word))
|
||||
{
|
||||
return $"[[{word}]]"; // Encerrar la palabra en corchetes si es técnica
|
||||
return $"[[{word}]]"; // Encerrar la palabra en corchetes si es técnica
|
||||
}
|
||||
return word; // Devolver la palabra sin modificar si no es técnica
|
||||
return word; // Devolver la palabra sin modificar si no es técnica
|
||||
});
|
||||
}
|
||||
|
||||
public string MarkTechnicalTerms_IgnoreCase(string text)
|
||||
{
|
||||
// Utilizar Regex para identificar palabras individualmente, ignorando mayúsculas y minúsculas
|
||||
// Utilizar Regex para identificar palabras individualmente, ignorando mayúsculas y minúsculas
|
||||
return Regex.Replace(text, @"\b(\w+)\b", match =>
|
||||
{
|
||||
string word = match.Groups[1].Value;
|
||||
// Verificar si la palabra está en el conjunto de términos técnicos, ignorando mayúsculas y minúsculas
|
||||
if (technicalTerms.Contains(word))
|
||||
// Verificar si la palabra está en el conjunto de términos técnicos, ignorando mayúsculas y minúsculas
|
||||
if (technicalTerms.Contains(word, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return $"[[{word}]]"; // Encerrar la palabra en corchetes si es técnica
|
||||
return $"[[{word}]]"; // Encerrar la palabra en corchetes si es técnica
|
||||
}
|
||||
return word; // Devolver la palabra sin modificar si no es técnica
|
||||
return word; // Devolver la palabra sin modificar si no es técnica
|
||||
}, RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
|
@ -248,12 +134,12 @@ namespace libObsidean
|
|||
return Regex.Replace(text, @"\[\[(.*?)\]\]", match =>
|
||||
{
|
||||
string word = match.Groups[1].Value;
|
||||
// Verificar si la palabra está en el conjunto de términos técnicos, ignorando mayúsculas y minúsculas
|
||||
// Verificar si la palabra está en el conjunto de términos técnicos, ignorando mayúsculas y minúsculas
|
||||
if (technicalTerms.Contains(word))
|
||||
{
|
||||
return word; // Devolver la palabra sin corchetes si es técnica
|
||||
return word; // Devolver la palabra sin corchetes si es técnica
|
||||
}
|
||||
return match.Value; // Devolver la palabra con corchetes si no es técnica
|
||||
return match.Value; // Devolver la palabra con corchetes si no es técnica
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -263,21 +149,15 @@ namespace libObsidean
|
|||
return Regex.Replace(text, @"\[\[(.*?)\]\]", match =>
|
||||
{
|
||||
string word = match.Groups[1].Value;
|
||||
// Verificar si la palabra está en el conjunto de términos técnicos, ignorando mayúsculas y minúsculas
|
||||
// Verificar si la palabra está en el conjunto de términos técnicos, ignorando mayúsculas y minúsculas
|
||||
if (technicalTerms.Contains(word.ToLowerInvariant(), StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return word; // Devolver la palabra sin corchetes si es técnica
|
||||
return word; // Devolver la palabra sin corchetes si es técnica
|
||||
}
|
||||
return match.Value; // Devolver la palabra con corchetes si no es técnica
|
||||
return match.Value; // Devolver la palabra con corchetes si no es técnica
|
||||
});
|
||||
}
|
||||
|
||||
public string RemoveDoubleBrackets(string text)
|
||||
{
|
||||
// Utilizar Regex para encontrar y remover los dobles corchetes
|
||||
// manteniendo solo el contenido dentro de ellos
|
||||
return Regex.Replace(text, @"\[\[(.*?)\]\]", "$1");
|
||||
}
|
||||
|
||||
public static string[,] ParseTableFromMarkdown(string filePath)
|
||||
{
|
||||
|
@ -312,33 +192,20 @@ namespace libObsidean
|
|||
if (tableLines.Count == 0)
|
||||
return new string[0, 0];
|
||||
|
||||
// Filtrar líneas que no sean separadores (líneas con solo guiones y pipes)
|
||||
var dataLines = tableLines.Where(line => !line.All(c => c == '|' || c == '-' || c == ' ')).ToList();
|
||||
|
||||
if (dataLines.Count == 0)
|
||||
return new string[0, 0];
|
||||
|
||||
// La primera línea es el header
|
||||
var header = dataLines[0].Split('|').Select(h => h.Trim()).Where(h => !string.IsNullOrEmpty(h)).ToArray();
|
||||
var header = tableLines[0].Split('|').Select(h => h.Trim()).Where(h => !string.IsNullOrEmpty(h)).ToArray();
|
||||
int columns = header.Length;
|
||||
int totalRows = dataLines.Count; // Incluye header + filas de datos
|
||||
int rows = tableLines.Count - 1;
|
||||
|
||||
string[,] tableArray = new string[totalRows, columns];
|
||||
string[,] tableArray = new string[rows, columns];
|
||||
|
||||
// Procesar todas las líneas (header + datos)
|
||||
for (int i = 0; i < totalRows; i++)
|
||||
for (int i = 1; i < rows; i++)
|
||||
{
|
||||
var rowParts = dataLines[i].Split('|').Select(p => p.Trim()).Where(p => !string.IsNullOrEmpty(p)).ToArray();
|
||||
|
||||
for (int j = 0; j < columns && j < rowParts.Length; j++)
|
||||
var row = tableLines[i+1].Split('|').ToArray();
|
||||
for (int j = 0; j < columns; j++)
|
||||
{
|
||||
tableArray[i, j] = rowParts[j];
|
||||
}
|
||||
|
||||
// Rellenar columnas faltantes con string vacío
|
||||
for (int j = rowParts.Length; j < columns; j++)
|
||||
{
|
||||
tableArray[i, j] = "";
|
||||
if (i >= rows || j >= columns || i<0 || j<0)
|
||||
return null;
|
||||
tableArray[i - 1, j] = row[j+1];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,12 +215,6 @@ namespace libObsidean
|
|||
public static void SaveTableToMarkdown(string filePath, string[,] tableArray)
|
||||
{
|
||||
var tableLines = ConvertArrayToTableLines(tableArray);
|
||||
// Asegurarse de que el directorio exista
|
||||
string? dir = Path.GetDirectoryName(filePath);
|
||||
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
File.WriteAllLines(filePath, tableLines);
|
||||
}
|
||||
|
||||
|
@ -389,4 +250,5 @@ namespace libObsidean
|
|||
return tableLines;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue