Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 756f8aa

Browse files
代码文件的 锚点 问题
1 parent 3453e33 commit 756f8aa

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

‎Coding_iOS/Controllers/CodeViewController.m‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,14 @@ - (void)refreshCodeViewData{
115115
[self.webContentView loadRequest:[NSURLRequest requestWithURL:imageUrl]];
116116
}else if ([@[@"file", @"sym_link", @"executable"] containsObject:_myCodeFile.file.mode]){
117117
NSString *contentStr = [WebContentManager codePatternedWithContent:_myCodeFile isEdit:NO];
118-
[self.webContentView loadHTMLString:contentStr baseURL:nil];
118+
[self.webContentView loadHTMLString:contentStr baseURL:[NSURLURLWithString:[selfp_baseHref]]];
119119
}
120120
}
121121

122+
- (NSString *)p_baseHref{//写在 html 文件里的,没有 baseHref 的话,锚点会异常
123+
return @"https://coding.net/";
124+
}
125+
122126
#pragma mark UIWebViewDelegate
123127
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
124128
DebugLog(@"strLink=[%@]",request.URL.absoluteString);
@@ -133,6 +137,10 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
133137
return YES;
134138
}
135139
}
140+
if ([request.URL.absoluteString isEqualToString:[self p_baseHref]] ||
141+
[request.URL.absoluteString hasPrefix:[[self p_baseHref] stringByAppendingString:@"#"]]) {
142+
return YES;
143+
}
136144
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:request.URL.absoluteString];
137145
if (vc) {
138146
[self.navigationController pushViewController:vc animated:YES];

‎Coding_iOS/Models/CodeFile.m‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,8 @@ - (NSDictionary *)toCreateParams{
105105

106106
@implementation CodeFile_RealFile
107107

108+
- (void)setPreview:(NSString *)preview{
109+
_preview = [preview stringByReplacingOccurrencesOfString:@"{{CodingUrl}}" withString:@""];
110+
}
111+
108112
@end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /