mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 06:56:10 +00:00
Bookmarks en markdown
This commit is contained in:
parent
ef5df06d02
commit
6413830117
7 changed files with 120 additions and 64 deletions
|
|
@ -9,6 +9,14 @@ namespace AideDeJeuLib
|
|||
{
|
||||
public class LinkItem : Item
|
||||
{
|
||||
public override string Markdown
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"\n\n<!--LinkItem-->\n\n{new string('#', NameLevel + 1)} {NameLink}\n\n<!--/LinkItem-->\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 $"<!--NameLink-->[{Name}]({Link})<!--/NameLink-->";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Item> items)
|
||||
{
|
||||
var serializer = ItemJsonSerializer;
|
||||
using(var stream = new MemoryStream())
|
||||
string md = string.Empty;
|
||||
md += "\n<!--Items-->\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<!--/Items-->\n";
|
||||
return md;
|
||||
}
|
||||
|
||||
public List<Item> ToItems(string md)
|
||||
{
|
||||
var item = Store.ToItem("", md);
|
||||
if(item is Items)
|
||||
{
|
||||
var items = item as Items;
|
||||
return items.ToList();
|
||||
}
|
||||
return new List<Item> { item };
|
||||
}
|
||||
|
||||
/*
|
||||
public string ToString(List<Item> 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<Item> ToItems(string str)
|
||||
{
|
||||
var serializer = ItemJsonSerializer;
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(str);
|
||||
using (var stream = new MemoryStream(byteArray))
|
||||
public List<Item> ToItems(string str)
|
||||
{
|
||||
return serializer.ReadObject(stream) as List<Item>;
|
||||
}
|
||||
}
|
||||
|
||||
public DataContractJsonSerializer ItemJsonSerializer
|
||||
{
|
||||
get
|
||||
{
|
||||
var settings = new DataContractJsonSerializerSettings();
|
||||
settings.KnownTypes = new List<Type>()
|
||||
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<Item>), settings);
|
||||
return serializer.ReadObject(stream) as List<Item>;
|
||||
}
|
||||
}
|
||||
|
||||
public DataContractJsonSerializer ItemJsonSerializer
|
||||
{
|
||||
get
|
||||
{
|
||||
var settings = new DataContractJsonSerializerSettings();
|
||||
settings.KnownTypes = new List<Type>()
|
||||
{
|
||||
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<Item>), settings);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
if (s != null)
|
||||
{
|
||||
var regex = new Regex("/(?<file>.*?)(_with_(?<with>.*))?\\.md(#(?<anchor>.*))?");
|
||||
var regex = new Regex("/?(?<file>.*?)(_with_(?<with>.*))?\\.md(#(?<anchor>.*))?");
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<string, Item> anchors, Item item)
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@
|
|||
|
||||
<Label Grid.Column="0" Grid.Row="1" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Margin="15,0,15,0" Style="{StaticResource subsubsection}" Text="Cette liste est vide, ajoutez des éléments à partir de la bibliothèque !" IsVisible="{Binding BookmarkCollection.Count, Converter={StaticResource IntToBooleanConverter}}" />
|
||||
|
||||
<ListView Grid.Column="0" Grid.Row="1" x:Name="ItemsListView" ItemsSource="{Binding BookmarkCollection}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}">
|
||||
<ListView Grid.Column="0" Grid.Row="1" x:Name="ItemsListView" ItemsSource="{Binding BookmarkCollection}" VerticalOptions="FillAndExpand" HasUnevenRows="true" CachingStrategy="RecycleElement" SelectedItem="{Binding SelectedItem}" ItemTapped="ItemsListView_ItemTapped">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell AutomationProperties.IsInAccessibleTree="True" AutomationId="machin" AutomationProperties.Name="hop">
|
||||
<StackLayout Padding="10" Orientation="Vertical">
|
||||
<Label Text="{Binding Name}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="16" />
|
||||
<Label Text="{Binding Id}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="12" />
|
||||
<Label Text="{Binding Link}" LineBreakMode="WordWrap" Style="{DynamicResource subsubsection}" FontSize="12" />
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using AideDeJeu.ViewModels;
|
||||
using AideDeJeuLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -19,5 +20,12 @@ namespace AideDeJeu.Views
|
|||
|
||||
BindingContext = DependencyService.Get<BookmarksViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
private async void ItemsListView_ItemTapped(object sender, ItemTappedEventArgs e)
|
||||
{
|
||||
var item = e.Item as LinkItem;
|
||||
var Main = DependencyService.Get<MainViewModel>();
|
||||
await Main.Navigator.NavigateToLinkAsync(item.Link);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue