1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 15:06:06 +00:00

Bookmarks en markdown

This commit is contained in:
Yan Maniez 2018-08-30 23:32:35 +02:00
parent ef5df06d02
commit 6413830117
7 changed files with 120 additions and 64 deletions

View file

@ -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;
}

View file

@ -87,6 +87,8 @@ namespace AideDeJeu.Tools
public static string IdFromName(string name)
{
string id = string.Empty;
if (name != null)
{
foreach (var c in name)
{
if (c >= 'A' && c <= 'Z')
@ -106,6 +108,7 @@ namespace AideDeJeu.Tools
id += c;
}
}
}
return id;
//return name.ToLower().Replace(" ", "-").Replace("\'","").Replace("/","");
//return RemoveDiacritics(name.ToLower().Replace(" ", "-").Replace("\'", ""));

View file

@ -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;
@ -91,6 +92,30 @@ namespace AideDeJeu.ViewModels
await App.Current.SavePropertiesAsync();
}
public string ToString(List<Item> items)
{
string md = string.Empty;
md += "\n<!--Items-->\n\n";
foreach(var item in items)
{
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;
@ -136,5 +161,6 @@ namespace AideDeJeu.ViewModels
return new DataContractJsonSerializer(typeof(List<Item>), settings);
}
}
*/
}
}

View file

@ -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
{

View file

@ -64,7 +64,10 @@ namespace AideDeJeu.ViewModels
if (IsClosingItem(block))
{
currentItem.Id = GetNewAnchorId(source, currentItem.Name);
if (currentItem.Id != null)
{
_AllItems[currentItem.Id] = currentItem;
}
return currentItem;
}
else if (IsNewItem(block))
@ -226,6 +229,8 @@ namespace AideDeJeu.ViewModels
public string GetNewAnchorId(string source, string name)
{
if (name != null)
{
var baseid = Helpers.IdFromName(name);
var id = $"{source}.md#{baseid}";
@ -240,6 +245,8 @@ namespace AideDeJeu.ViewModels
name = $"{source}.md#{baseid}{index}";
}
}
return null;
}
/*
void AddAnchor(string source, Dictionary<string, Item> anchors, Item item)
{

View file

@ -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>

View file

@ -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);
}
}
}