diff --git a/MarkdownTableParser.cs b/MarkdownTableParser.cs new file mode 100644 index 0000000..8a1dbf3 --- /dev/null +++ b/MarkdownTableParser.cs @@ -0,0 +1,60 @@ +using System.Text.RegularExpressions; +using System.IO; +using Newtonsoft.Json.Linq; + +namespace libObsidean +{ + public class MarkdownTableParser + { + public static string[,] ParseTableFromMarkdown(string filePath) + { + var lines = File.ReadAllLines(filePath); + var tableLines = ExtractTableLines(lines); + return ConvertTableLinesToArray(tableLines); + } + + private static List ExtractTableLines(string[] lines) + { + List tableLines = new List(); + bool inTable = false; + + foreach (var line in lines) + { + if (line.StartsWith("|") && line.EndsWith("|")) + { + inTable = true; + tableLines.Add(line.Trim()); + } + else if (inTable) + { + break; + } + } + + return tableLines; + } + + private static string[,] ConvertTableLinesToArray(List tableLines) + { + if (tableLines.Count == 0) + return new string[0, 0]; + + var header = tableLines[0].Split('|').Select(h => h.Trim()).Where(h => !string.IsNullOrEmpty(h)).ToArray(); + int columns = header.Length; + int rows = tableLines.Count - 1; + + string[,] tableArray = new string[rows, columns]; + + for (int i = 1; i <= rows; i++) + { + var row = tableLines[i].Split('|').Select(r => r.Trim()).Where(r => !string.IsNullOrEmpty(r)).ToArray(); + for (int j = 0; j < columns; j++) + { + tableArray[i - 1, j] = row[j]; + } + } + + return tableArray; + } + } +} diff --git a/Obsidean.cs b/Obsidean.cs new file mode 100644 index 0000000..ba4fb06 --- /dev/null +++ b/Obsidean.cs @@ -0,0 +1,140 @@ + +using System.Text.RegularExpressions; +using System.IO; +using Newtonsoft.Json.Linq; + +namespace libObsidean +{ + internal class Obsidean + { + static HashSet technicalTerms; + + static string GetObsidianConfigPath() + { + string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + return Path.Combine(appDataPath, "obsidian", "obsidian.json"); + } + + static string GetVaultPath(string vaultName) + { + try + { + string pathToJsonFile = GetObsidianConfigPath(); + string jsonContent = File.ReadAllText(pathToJsonFile); + JObject jsonObject = JObject.Parse(jsonContent); + JObject vaults = (JObject)jsonObject["vaults"]; + + foreach (var vault in vaults) + { + // 'vault' es un KeyValuePair + // 'vault.Key' es la clave (ID del vault), 'vault.Value' es el valor (detalles del vault como JToken) + string path = (string)vault.Value["path"]; + if (!string.IsNullOrEmpty(path)) + { + // 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)) + { + return path; + } + } + } + } + catch (Exception ex) + { + Console.WriteLine("Error al leer o parsear el archivo JSON: " + ex.Message); + } + return null; + } + + public void LeerPalabrasTecnicas() + { + // "C:\Users\migue\OneDrive\Miguel\Obsidean\Trabajo\VM\Palabras Tecnicas\Lista.md" + string pathToMarkdown = GetVaultPath("VM"); + if (!string.IsNullOrEmpty(pathToMarkdown)) + { + string pathToLista = pathToMarkdown + "\\Palabras Tecnicas\\Lista.md"; + string[] lines = File.ReadAllLines(pathToLista); + technicalTerms = ExtractTechnicalTerms(lines); + } + + // Ahora puedes usar technicalTerms para tu lógica de corrección + } + + public HashSet ExtractTechnicalTerms(string[] lines) + { + var terms = new HashSet(); + foreach (var line in lines) + { + // Suponiendo que cada línea contiene un término técnico + terms.Add(line.Trim()); + } + return terms; + } + + public string MarkTechnicalTerms(string text) + { + // Utilizar Regex para identificar palabras individualmente + 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 + if (technicalTerms.Contains(word)) + { + return $"[[{word}]]"; // Encerrar la palabra en corchetes si 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 + 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, StringComparer.OrdinalIgnoreCase)) + { + return $"[[{word}]]"; // Encerrar la palabra en corchetes si es técnica + } + return word; // Devolver la palabra sin modificar si no es técnica + }, RegexOptions.IgnoreCase); + } + + public string RemoveTechnicalTermMarkers(string text) + { + // Utilizar Regex para encontrar y remover los dobles corchetes + 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 + if (technicalTerms.Contains(word)) + { + return word; // Devolver la palabra sin corchetes si es técnica + } + return match.Value; // Devolver la palabra con corchetes si no es técnica + }); + } + + public string RemoveTechnicalTermMarkers_IgnoreCase(string text) + { + // Utilizar Regex para encontrar y remover los dobles corchetes + 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 + if (technicalTerms.Contains(word.ToLowerInvariant(), StringComparer.OrdinalIgnoreCase)) + { + return word; // Devolver la palabra sin corchetes si es técnica + } + return match.Value; // Devolver la palabra con corchetes si no es técnica + }); + } + + + } + + +} diff --git a/libObsidean.csproj b/libObsidean.csproj new file mode 100644 index 0000000..e8607f5 --- /dev/null +++ b/libObsidean.csproj @@ -0,0 +1,14 @@ + + + + net8.0-windows + enable + true + enable + + + + + + + diff --git a/libObsidean.sln b/libObsidean.sln new file mode 100644 index 0000000..44b6528 --- /dev/null +++ b/libObsidean.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libObsidean", "libObsidean.csproj", "{4ACE89C1-A9B4-4FE2-95F5-1CCAE33EE49F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4ACE89C1-A9B4-4FE2-95F5-1CCAE33EE49F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4ACE89C1-A9B4-4FE2-95F5-1CCAE33EE49F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4ACE89C1-A9B4-4FE2-95F5-1CCAE33EE49F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4ACE89C1-A9B4-4FE2-95F5-1CCAE33EE49F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7DA7078A-5FED-4F78-AFA6-75A996E43BFB} + EndGlobalSection +EndGlobal