diff --git a/AideDeJeu/AideDeJeu/Models/LinkItem.cs b/AideDeJeu/AideDeJeu/Models/LinkItem.cs index b55723ce..d517372d 100644 --- a/AideDeJeu/AideDeJeu/Models/LinkItem.cs +++ b/AideDeJeu/AideDeJeu/Models/LinkItem.cs @@ -9,6 +9,14 @@ namespace AideDeJeuLib { public class LinkItem : Item { + public override string Markdown + { + get + { + return $"\n\n\n\n{new string('#', NameLevel + 1)} {NameLink}\n\n\n\n"; + } + set => base.Markdown = value; + } public string Link { get; set; } public string NameLink { @@ -16,7 +24,7 @@ namespace AideDeJeuLib { if (Name != null && Link != null) { - return $"[{Name}]({Link})"; + return $"[{Name}]({Link})"; } return null; } diff --git a/AideDeJeu/AideDeJeu/Tools/Helpers.cs b/AideDeJeu/AideDeJeu/Tools/Helpers.cs index ffd3968b..bf5aa73a 100644 --- a/AideDeJeu/AideDeJeu/Tools/Helpers.cs +++ b/AideDeJeu/AideDeJeu/Tools/Helpers.cs @@ -87,23 +87,26 @@ namespace AideDeJeu.Tools public static string IdFromName(string name) { string id = string.Empty; - foreach(var c in name) + if (name != null) { - if(c >= 'A' && c <= 'Z') + foreach (var c in name) { - id += c.ToString().ToLower(); - } - else if(c == ' ') - { - id += '-'; - } - else if(c== '\'' || c == '/' || c == '(' || c ==')' || c == ':' || c == '+' || c == ',') - { - // vide - } - else - { - id += c; + if (c >= 'A' && c <= 'Z') + { + id += c.ToString().ToLower(); + } + else if (c == ' ') + { + id += '-'; + } + else if (c == '\'' || c == '/' || c == '(' || c == ')' || c == ':' || c == '+' || c == ',') + { + // vide + } + else + { + id += c; + } } } return id; diff --git a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs index ed4cdcf2..edd0bbfb 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/BookmarksViewModel.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; +using System.Linq; using System.Runtime.Serialization.Json; using System.Text; using System.Threading.Tasks; @@ -93,48 +94,73 @@ namespace AideDeJeu.ViewModels public string ToString(List items) { - var serializer = ItemJsonSerializer; - using(var stream = new MemoryStream()) + string md = string.Empty; + md += "\n\n\n"; + foreach(var item in items) { - serializer.WriteObject(stream, items); - stream.Seek(0, SeekOrigin.Begin); - using (StreamReader reader = new StreamReader(stream)) + md += item.Markdown; + } + md += "\n\n\n"; + return md; + } + + public List ToItems(string md) + { + var item = Store.ToItem("", md); + if(item is Items) + { + var items = item as Items; + return items.ToList(); + } + return new List { item }; + } + + /* + public string ToString(List items) + { + var serializer = ItemJsonSerializer; + using(var stream = new MemoryStream()) { - return reader.ReadToEnd(); + serializer.WriteObject(stream, items); + stream.Seek(0, SeekOrigin.Begin); + using (StreamReader reader = new StreamReader(stream)) + { + return reader.ReadToEnd(); + } } } - } - public List ToItems(string str) - { - var serializer = ItemJsonSerializer; - byte[] byteArray = Encoding.UTF8.GetBytes(str); - using (var stream = new MemoryStream(byteArray)) + public List ToItems(string str) { - return serializer.ReadObject(stream) as List; - } - } - - public DataContractJsonSerializer ItemJsonSerializer - { - get - { - var settings = new DataContractJsonSerializerSettings(); - settings.KnownTypes = new List() + var serializer = ItemJsonSerializer; + byte[] byteArray = Encoding.UTF8.GetBytes(str); + using (var stream = new MemoryStream(byteArray)) { - typeof(HomeItem), - typeof(Spell), - typeof(Monster), - //typeof(Items), - typeof(LinkItem), - typeof(Equipment), - //typeof(Spells), - //typeof(Monsters), - //typeof(Equipments), - typeof(PageItem), - }; - return new DataContractJsonSerializer(typeof(List), settings); + return serializer.ReadObject(stream) as List; + } } + + public DataContractJsonSerializer ItemJsonSerializer + { + get + { + var settings = new DataContractJsonSerializerSettings(); + settings.KnownTypes = new List() + { + typeof(HomeItem), + typeof(Spell), + typeof(Monster), + //typeof(Items), + typeof(LinkItem), + typeof(Equipment), + //typeof(Spells), + //typeof(Monsters), + //typeof(Equipments), + typeof(PageItem), + }; + return new DataContractJsonSerializer(typeof(List), settings); + } + } + */ } } -} diff --git a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs index 7623c030..459c90bc 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs @@ -140,7 +140,7 @@ namespace AideDeJeu.ViewModels { if (s != null) { - var regex = new Regex("/(?.*?)(_with_(?.*))?\\.md(#(?.*))?"); + var regex = new Regex("/?(?.*?)(_with_(?.*))?\\.md(#(?.*))?"); var match = regex.Match(s); var file = match.Groups["file"].Value; var anchor = match.Groups["anchor"].Value; @@ -181,6 +181,10 @@ namespace AideDeJeu.ViewModels { await GotoItemDetailPageAsync(item); } + var tabbedPage = App.Current.MainPage as MainTabbedPage; + tabbedPage.SelectedItem = null; + tabbedPage.SelectedItem = tabbedPage.MainNavigationPage; + } else { diff --git a/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs index edc3719d..38863f48 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/StoreViewModel.cs @@ -64,7 +64,10 @@ namespace AideDeJeu.ViewModels if (IsClosingItem(block)) { currentItem.Id = GetNewAnchorId(source, currentItem.Name); - _AllItems[currentItem.Id] = currentItem; + if (currentItem.Id != null) + { + _AllItems[currentItem.Id] = currentItem; + } return currentItem; } else if (IsNewItem(block)) @@ -227,18 +230,22 @@ namespace AideDeJeu.ViewModels public string GetNewAnchorId(string source, string name) { - var baseid = Helpers.IdFromName(name); - var id = $"{source}.md#{baseid}"; - int index = 0; - while (true) + if (name != null) { - if (!_AllItems.ContainsKey(name)) + var baseid = Helpers.IdFromName(name); + var id = $"{source}.md#{baseid}"; + int index = 0; + while (true) { - return id; + if (!_AllItems.ContainsKey(name)) + { + return id; + } + index++; + name = $"{source}.md#{baseid}{index}"; } - index++; - name = $"{source}.md#{baseid}{index}"; } + return null; } /* void AddAnchor(string source, Dictionary anchors, Item item) diff --git a/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml b/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml index c3c44385..72137d5e 100644 --- a/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/BookmarksPage.xaml @@ -20,13 +20,13 @@